Could someone explain the concept behind how to pass data between asynchronous calls in python?
I have this scenario:
I have a main procedure (mainthread) and then I run another async call that adds two numbers() and sleeps for some time. The expectation is to have main thread wait until calc and sleeping are done. In terms of pseudo code this might look like this:
def example():
def my_calc(x,y):
z = x+ y
time.sleep(2)
return z #this should get pushed to queue, but for simplicity we use 'return z'
z = asyncSomething.callInThread(my_calc, 2, 20) #assume we get z from queue
return z+10
def runner(): #our main function
print 'start'
z = example()
print 'result is {0}'.format(z)
How do I made the last print wait for z? I tried to use threading.Event() and played with set, wait, and clear, but they block everything.
I do not think my case is unique and there has to be a neat systematic way of doing it. I looked into twisted reactor but it was partially successful. My actual code involved GUI that has to wait for results from async processes and then self- and auto- update...but I think the example depicts the bulk of the problem
I think I am missing the actual concept of how to work asynchronously in python.