百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
返回工具页/返回 Issues 列表
#21151·cherry-studio

[错误]: 当折叠/展开时,长的代码块可能会重叠或显示混乱的内容

作者: ilcpm创建于 2026年9月28日更新于 2026年9月29日
标签bugp2windowsui-ux

import threading, time from collections import deque class BoundedBuffer: # This class is a thread def init(self, n): self.buf = deque() # Shared data: only accessible through put/get self.n = n self.lock = threading.Lock() # The entry lock of the thread self.not_full = threading.Condition(self.lock) # Condition variable: the buffer is not full self.not_empty = threading.Condition(self.lock) # Condition variable: the buffer is not empty def put(self, item): with self.lock: # Enter the thread (others are in it, so wait at this line) while len(self.buf) == self.n: self.not_full.wait() # Full: temporarily leave the thread to wait, let others enter self.buf.append(item) print(f"Produced {item}, buffer: {list(self.buf)}") self.not_empty.notify() # Wake up a thread waiting for "not empty" # Exit the with block = leave the thread

内容来源: CherryHQ/cherry-studio

查看 GitHub 原文在 GitHub 查看讨论