import _thread #线程
import time
signal_value = 0
def th1():
a = 0
global signal_value
while(1):
if(signal_value == 0):
print("a")
signal_value = 1
a+=1
if(a > 9):
break
time.sleep(1)
return
def th2():
a = 0
global signal_value
while(1):
if(signal_value == 1):
print("b")
signal_value = 2
a+=1
if(a > 9):
break
time.sleep(1)
return
def th3():
a = 0
global signal_value
while(1):
if(signal_value == 2):
print("c")
signal_value = 3
a+=1
if(a > 9):
break
time.sleep(1)
return
def th4():
a = 0
global signal_value
while(1):
if(signal_value == 3):
print("d")
signal_value = 0
a+=1
if(a > 9):
break
time.sleep(1)
return
def main():
try:
_thread.start_new_thread( th1, ())
_thread.start_new_thread( th2, ())
_thread.start_new_thread( th3, ())
_thread.start_new_thread( th4, ())
except Exception as e:
print("---异常---:", e)
while 1:
pass
return
main()
还需完善修改