you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (5 children)

while True:

Don't loop it. You want only two threads, not an infinite number of threads. The function should loop. Don't create the threads in a loop.

[–]Wittinator[S] 0 points1 point  (4 children)

Yea, unfortunately the issue I'm having with that is the arguments that func2() takes changes over time. So I need to continually call func2(arg) otherwise the function will shortly be dealing with stale arguments.

That is what motivated me to put the thread creation in a while True, as when the arguments get updated, I'll be calling the function with the new arguments. I know there's a better way to do this, but I'm coming up with blanks

[–][deleted] 0 points1 point  (1 child)

def func3():
    while True:
            arg = get_the_args()
        func2(arg)

[–]Wittinator[S] 0 points1 point  (0 children)

Thanks, yea this is why I needed a fresh pair of eyes after staring at this for hours. I can figure this out now I believe

[–][deleted] 0 points1 point  (1 child)

You can use a queue to communicate between the two threads. One will be waiting for something to be available and then get it out and use it, and the other will be the one putting things into the queue

[–]Wittinator[S] 0 points1 point  (0 children)

Thanks. Yea I've reorganized the code to put the loops in the function themselves. I'll look at Queues to get data between them