Z
Z
zhyeba2022-04-20 19:26:32
Python
zhyeba, 2022-04-20 19:26:32

Is it possible to start processing a directory with images in the "background"?

There is a certain script that in a cycle (permanently) takes certain screenshots and adds them to a certain directory.
conditionally,

if __name__ == '__main__':
  while running:
    for user_coordinates in users_coordinates:
      do_user_shop_screen(position)


Is it possible somehow "background", from the same script, to start processing the directory where these images are added, while not making the process of creating these screenshots wait?
Or would it be correct to do this via asyncio immediately after creating this screenshot?

The problem is that sequential creation of a screenshot and reading information from it (opencv + tesseract) takes a lot of time. It is necessary to somehow parallelize these processes, but to be honest, I still don’t quite understand how to do it correctly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-04-20
@Vindicar

multiprocessing. But keep in mind that this will only help on a multi-core machine, and then only conditionally. You need to measure how often you take screenshots, and how long it takes to process them. If the processing takes 2-3 times longer than the arrival of new screenshots, then you can get out. If not, then you need to optimize processing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question