日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 多线程读写文件错误_python多线程老是报错。大神帮忙看看哈?

發布時間:2023/12/10 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 多线程读写文件错误_python多线程老是报错。大神帮忙看看哈? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以下是代碼:importthreadingimporttimeproducts=[]condition=threading.Condition()classConsumer(threading.Thread):defconsume(self):globalconditionglobalproductsconditon.acqu...

以下是代碼:

import threading

import time

products=[]

condition = threading.Condition()

class Consumer(threading.Thread):

def consume(self):

global condition

global products

conditon.acquire()

if len(products)==0:

condition.wait()

print('消費提醒:沒有產品去消費了')

products.pop()

print('消費者提醒:消費1個產品')

print('消費者提醒:還能消費的產品數為'+str(len(products)))

condition.notify()

condition.release()

def run(self):

for i in range(0,20):

time.sleep(4)

self.consume()

class Producer(threading.Thread):

def produce(self):

global condition

global products

condition.acquire()

if len(products)==10:

condition.wait()

print('生產者提醒:生成的產品數為'+str(len(products)))

print('生產者提醒:停止生產!')

products.append(1)

print('生產者提醒:產品總數為'+str(len(products)))

condition.notify()

condition.release()

def run(self):

for i in range(0,20):

time.sleep(1)

self.produce()

producer=Producer()

consumer=Consumer()

consumer.start()

producer.start()

producer.join()

consumer.join()

報錯的提示:

Exception in thread Thread-2:

Traceback (most recent call last):

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner

self.run()

File "C:/Users/Administrator/AppData/Local/Programs/Python/Python38-32/對對對.py", line 22, in run

self.consume()

File "C:/Users/Administrator/AppData/Local/Programs/Python/Python38-32/對對對.py", line 10, in consume

conditon.acquire()

NameError: name 'conditon' is not defined

展開

總結

以上是生活随笔為你收集整理的python 多线程读写文件错误_python多线程老是报错。大神帮忙看看哈?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。