#coding=utf8
#定义全局变量,初始值为 False
isflag = False
#coding=utf8
from ggg import *
import threading
import time
class mmm(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
global isflag
print 'mmm isflag id: ', id(isflag)
print 'mmm isflag: ', isflag
while not isflag:
print 'mmm isflag id: ', id(isflag)
print 'mmm isflag: ', isflag
print 'sleep...\n'
time.sleep(0.5)
print 'sleep end\n'
#coding=utf8
from ggg import *
import threading
import time
import mmm
class subc(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
print 'sleep 3s...\n'
time.sleep(3)
print 'sleep 3s end\n'
global isflag
print 'subc isflag id: ', id(isflag)
isflag = True
print 'subc isflag: ', isflag
t2 = mmm.mmm()
t2.setDaemon(True)
t2.start()
t1 = subc()
t1.setDaemon(True)
t1.start()
t2.join()
print '---'
1
billgreen1 2016-01-19 19:30:30 +08:00
我最近也在看多进程 /多线程问题,请把问题用 markown 再发一遍,谢谢。
|
2
haofly 2016-01-19 21:12:14 +08:00
要改变全局变量得用锁啊
|
3
mengzhuo 2016-01-20 07:23:35 +08:00 via iPhone
改成
import ggg ggg.isflag = xxx |
4
defias OP 3 楼的果然可以哦
|