0

I have list of co-ordinates where I have to emulate a mouse click using pyautogui. Those co-ordinates are retrieved from live video stream basically from frames. So emulating a mouse click for each frames isn't fast enough.

So what I plan to do is:

  • Add co-ordinates to an array/deque from each frame.

  • Then (maybe) create a thread where I can loop through the array and emulate a mouse click in order which will not block the main thread.

Will this solve the problem? Is there any other way to perform clicks fast using pyautogui?

(I am not familiar with multi threading)

HansHirse
  • 18,010
  • 10
  • 38
  • 67
Saqib
  • 23
  • 2

1 Answers1

0

I think it depends, This is def a common pattern for distributing work. Is your workload CPU bound? If so threads won't help you scale out because of GIL contention. If it is IO bound than threads may be a good place to start.

With a thread pool pattern you'd fan out work just as you outline:

  • enqueue work without blocking from the main thread, and then then consumer threads would be reading from the queue in a loop.

If your processing is CPU bound than a multiprocessing pool using the same pattern might help:

Multiprocessing DOES provide a pool abstraction, and it would be the same thing except the queue would require some sort of interprocess communication (handled by multiprocessing queue)

https://docs.python.org/2/library/multiprocessing.html#using-a-pool-of-workers

Each should be relatively easy to setup and it should be pretty easy to benchmark each to see if they offer performance improvements.

dm03514
  • 54,664
  • 18
  • 108
  • 145
  • I didn't quite understand everything but I will look into pool pattern online then post the results. – Saqib Mar 15 '19 at 04:19
  • My workload is IO bound since I have to get data from video frame. Also the mouse clicking action is IO dependent. – Saqib Mar 15 '19 at 04:21