enteracity
json_wuwu
2019-03-21 17:09

python3.7 互斥锁问题

  • python

acquire(),release()Pycharm提示没有参数,原来不是不用传参数的吗?

import threading
import time
num =0
tepe1 = threading.Lock
def f1():
for i in range(1000000):
global num
tepe1.acquire()
num += 1
tepe1.release()
print(num)

def f2():
for y in range(1000000):
global num
tepe1.acquire()
num += 1
tepe1.release()
print(num)
#创建锁

t = threading.Thread(target=f1)
t1 = threading.Thread(target=f2)

t.start()
t1.start()
print(num)

结果:AttributeError: 'builtin_function_or_method' object has no attribute 'acquire'

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐