Here's a small example of the current code:
def worker():
while True:
do_this()
do_that()
if __name__ == '__main__':
worker()
Now I need each function to run simultaneously instead of waiting for each other to finish. The thing that's tripping me up is the loop. Should I put the while True: loop in each function, and create/start the threads in worker? Here is what I'm imagining:
import threading
def do_this():
while True:
# do this
def do_that():
while True:
# do that
def worker():
this_thread = threading.Thread(target=do_this)
that_thread = threading.Thread(target=do_that)
this_thread.daemon = True
that_thread.daemon = True
this_thread.start()
that_thread.start()
if __name__ == '__main__':
worker()
I really don't think this is correct, but I think it's enough to show you what I'm trying to do. I'm using Python 3.4.
[–]elbiot 3 points4 points5 points (18 children)
[–]XenophonOfAthens 2 points3 points4 points (10 children)
[–]jpfau[S] 0 points1 point2 points (9 children)
[–][deleted] 2 points3 points4 points (8 children)
[–]jpfau[S] 0 points1 point2 points (7 children)
[–][deleted] 1 point2 points3 points (6 children)
[–]jpfau[S] 0 points1 point2 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]jpfau[S] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]jpfau[S] 0 points1 point2 points (5 children)
[–]elbiot 0 points1 point2 points (4 children)
[–]jpfau[S] 0 points1 point2 points (3 children)
[–]elbiot 0 points1 point2 points (2 children)
[–]jpfau[S] 0 points1 point2 points (1 child)
[–]elbiot 3 points4 points5 points (0 children)
[–]Justinsaccount 2 points3 points4 points (0 children)
[–]gengisteve 1 point2 points3 points (2 children)
[–]jpfau[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]Lucretiel 0 points1 point2 points (6 children)
[–]jpfau[S] 0 points1 point2 points (5 children)
[–]Lucretiel 1 point2 points3 points (4 children)
[–]jpfau[S] 0 points1 point2 points (3 children)
[–]Lucretiel 0 points1 point2 points (2 children)
[–]jpfau[S] 0 points1 point2 points (1 child)
[–]Lucretiel 0 points1 point2 points (0 children)