[root@yyjk ~/sbin/F5]#cat test4.py
import threading
import time
threads = []
def fun9():
x=100
time.sleep(1)
x= x+1;
print x
return x
def fun10():
time.sleep(18)
x=x+4
print x
return x;
t9 = threading.Thread(target=fun9,name='fun9')
threads.append(t9)
t10 = threading.Thread(target=fun10,name='fun10')
threads.append(t10)
for t in threads:
t.setDaemon(True)
t.start()
for t in threads:
t.join()
[root@yyjk ~/sbin/F5]#time python test4.py
101
Exception in thread fun10:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "test4.py", line 15, in fun10
x=x+4
UnboundLocalError: local variable 'x' referenced before assignment
real 0m18.039s
user 0m0.017s
sys 0m0.005s