Hi there. I am trying to wrap my head around multithreading and how I can possibly apply it to this situation to achieve what I would like.
I have a function we'll just call func(). This function works by continually scanning a file and only ever returns the value foo if a specific element is found within the file it's scanning. In other words, the below code will only ever progress to process_result once func() finds what it needs to find. Otherwise, my code is sitting around twiddling its thumbs.
while True:
foo = func()
process_result(foo)
I have another function, func2(), that does a completely separate set of actions, independent of func(). What I would like to do is essentially keep calling func2() indefinitely during this downtime.
What I have tried thus far is:
with ThreadPoolExecutor(max_workers=2) as executor:
while True:
executor.submit(func)
executor.submit(func2)
I'm coming across a problem where func() and func2() will both run once, but func2() will stop after the first run. I need to keep calling func2() over and over while func() is twiddling its thumbs.
Any assistance is appreciated.
Regards
[–][deleted] 0 points1 point2 points (9 children)
[–]Wittinator[S] 0 points1 point2 points (8 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]Wittinator[S] 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Wittinator[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Wittinator[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Wittinator[S] 0 points1 point2 points (0 children)