import threading
import time
class thread1(threading.Thread):
def __init__(self):
super(thread1, self).__init__()
def run(self):
def r():
for i in range(ord('a'), ord('z')+1):
print chr(i)
print chr(i)
print chr(i)
r()
class thread2(threading.Thread):
def __init__(self):
super(thread2, self).__init__()
def run(self):
def r():
for i in range(1,27):
print i
r()
def main():
t1 = thread1()
t2 = thread2()
t1.start()
t2.start()
t1.join()
t2.join()
if __name__ == '__main__':
main()
我想让t1打印三个字母后t2再打一个数字,但是这段代码的执行效果是t1每打印一个字母t2就会紧接着打印一个数字,请问python多线程执行的时候如何控制线程执行语句块的粒度,或者说有没有什么其他办法能够满足我的要求,必须要是多线程的。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
Lock, Condition, Event, etc.
为什么不会多线程却又非要用多线程呢?