Created
April 5, 2019 03:01
-
-
Save chavarera/d86a806ecfbb07c55711d0828056c69b to your computer and use it in GitHub Desktop.
pythonthreading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
def Func1(num): | |
cal=num*10000 | |
print("\nI am From Func1 ") | |
def Func2(num): | |
print("\nI am from Func2".format(num * num)) | |
if __name__ == "__main__": | |
t1 = threading.Thread(target=Func1, args=(10,)) | |
t2=threading.Thread(target=Func2,args=(11,)) | |
t1.start() | |
t2.start() | |
t1.join() | |
t2.join() | |
print("\nDone") | |
import queue | |
from threading import Thread | |
def foo(bar): | |
print('hello {0}'.format(bar)) | |
return 'foo' | |
que = queue.Queue() | |
fn=lambda q,arg1:q.put(foo(arg1)) | |
t = Thread(target=fn, args=(que, 'world!')) | |
t.start() | |
t.join() | |
result = que.get() | |
print(result) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment