I have two function (func_1 & func_2). I want to run that two functions simultaneously but in different threads using the "threading" module. Now I want to use the result from func_1 to func_2 recursively. For example, func_1 downloading images from the website continuously and sends those images to func_2 and then func_2 process those images continuously & save those processed images in local drive. That's what my aim is. I'm new to Python so could somebody explain how to do it. I've some sample a program so that it will be clear what I'm trying to do. Thanks.
def func_1():
while True:
#downloading images from net & sends to func_2
def func_2():
#getting result from func_1 and process them recursively
t1=threading.Thread(target=func_1)
t2=threading.Thread(target=func_2)
Roy,
I'm myself not the biggest threading specialist, but I would like to stress some parts in your question, which are unclear or phony (for me personaly):
Now I want to use the result from func_1 to func_2 recursively.
This is not a recursion, but the so called producer-consumer or some type of synchronization thread. To be more precise I've looked at the precise recursion definition in merriam-webster :
relating to, or constituting a procedure that can repeat itself indefinitely
which wouldn't be the pure meaning in this case.
func_1 downloading images from the website continuously and sends those images to func_2 and then func_2 process those images continuously..
Does it mean that your thread1 shouldn't wait for the successful processing in thread2 ? If so I suggest you to look at this page under Producer-Consumer .
Actually the whole article is very good in my opinion, good luck:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.