本文整理汇总了Python中queue.Queue.close方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.close方法的具体用法?Python Queue.close怎么用?Python Queue.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类queue.Queue
的用法示例。
在下文中一共展示了Queue.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from queue import Queue [as 别名]
# 或者: from queue.Queue import close [as 别名]
class Reference:
def __init__(self, id):
self.id = id
self.chunks = Queue(0)
def close(self):
self.chunks.close()
def append(self, bytes):
self.chunks.put(bytes)
def get_chunk(self):
return self.chunks.get()
def get_complete(self):
data = ""
for chunk in self:
data += chunk
return data
def next(self):
try:
return self.get_chunk()
except Closed, e:
raise StopIteration
示例2: __init__
# 需要导入模块: from queue import Queue [as 别名]
# 或者: from queue.Queue import close [as 别名]
class Peer:
def __init__(self, conn, delegate, channel_factory=None, channel_options=None):
self.conn = conn
self.delegate = delegate
self.outgoing = Queue(0)
self.work = Queue(0)
self.channels = {}
self.lock = threading.Lock()
if channel_factory:
self.channel_factory = channel_factory
else:
self.channel_factory = Channel
if channel_options is None:
channel_options = {}
self.channel_options = channel_options
def channel(self, id):
self.lock.acquire()
try:
try:
ch = self.channels[id]
except KeyError:
ch = self.channel_factory(id, self.outgoing, self.conn.spec, self.channel_options)
self.channels[id] = ch
finally:
self.lock.release()
return ch
def start(self):
self.writer_thread = threading.Thread(target=self.writer)
self.writer_thread.daemon = True
self.writer_thread.start()
self.reader_thread = threading.Thread(target=self.reader)
self.reader_thread.daemon = True
self.reader_thread.start()
self.worker_thread = threading.Thread(target=self.worker)
self.worker_thread.daemon = True
self.worker_thread.start()
def fatal(self, message=None):
"""Call when an unexpected exception occurs that will kill a thread."""
self.closed("Fatal error: %s\n%s" % (message or "", traceback.format_exc()))
def reader(self):
try:
while True:
try:
frame = self.conn.read()
except EOF, e:
self.work.close()
break
ch = self.channel(frame.channel)
ch.receive(frame, self.work)
except VersionError, e:
self.closed(e)
except: