python 锁问题
问题:写两个线程,一个线程打印1~52,另一个线程打印A~Z,打印顺序是12A34B...5152Z;
from threading import Thread,Lock
import time
num = 1
def print_num():
global num
for x in range(1,53):
if num%3!=0:
c.acquire()
print(x)
num+=1
c.release()
def print_alpha():
global num
for i in range(ord("A"),ord("Z")+1):
if num%3==0:
c.acquire()
print(chr(i))
num+=1
c.release()
c = Lock()
a = Thread(target=print_num)
a.start()
b = Thread(target=print_alpha)
b.start()
运行结果显示1,2。不知道错在哪
求大神指教