本文整理汇总了Python中gofer.common.Thread.aborted方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.aborted方法的具体用法?Python Thread.aborted怎么用?Python Thread.aborted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gofer.common.Thread
的用法示例。
在下文中一共展示了Thread.aborted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_aborted
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def test_aborted(self, current):
thread = GThread()
current.return_value = thread
event = getattr(thread, thread.ABORT)
self.assertEqual(GThread.aborted(), event.isSet())
# abort
event.set()
self.assertEqual(GThread.aborted(), event.isSet())
示例2: run
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def run(self):
"""
Run actions.
"""
while not Thread.aborted():
for plugin in Plugin.all():
for action in plugin.actions:
plugin.pool.run(action)
sleep(10)
示例3: run
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def run(self):
"""
Thread main.
"""
delay = self._precision
while not Thread.aborted():
sleep(delay)
for tracker in self.paths():
self._sniff(tracker)
示例4: open
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def open(self):
"""
Open the reader.
"""
while not Thread.aborted():
try:
self.reader.open()
break
except Exception:
log.exception(self.getName())
sleep(30)
示例5: _fn
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def _fn(thing, *args, **kwargs):
repair = lambda: None
while not Thread.aborted():
try:
repair()
return fn(thing, *args, **kwargs)
except _NotFound, e:
raise NotFound(*e.args)
except LinkError:
sleep(DELAY)
repair = thing.repair
示例6: accept
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def accept(self, socket):
"""
Accept requests.
:param socket: An open socket.
:type socket: socket.socket
"""
while not Thread.aborted():
client, address = socket.accept()
try:
self.accepted(client)
finally:
client.close()
示例7: run
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def run(self):
"""
Main consumer loop.
"""
self.reader = Reader(self.node, self.url)
self.reader.authenticator = self.authenticator
self.open()
try:
while not Thread.aborted():
self.read()
finally:
self.close()
示例8: run
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def run(self):
"""
Read the pending queue and dispatch requests
to the plugin thread pool.
"""
while not Thread.aborted():
request = self.pending.get()
try:
task = Task(self.plugin, request, self.pending.commit)
self.plugin.pool.run(task)
except Exception:
self.pending.commit(request.sn)
log.exception(request.sn)
示例9: purge
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def purge(self, url=None):
"""
Purge (drain) all queued messages.
:param url: The broker URL.
:type url: str
"""
url = url or self.url
with Reader(self, url=url) as reader:
while not Thread.aborted():
message = reader.get()
if message:
message.ack()
else:
break
示例10: run
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def run(self):
"""
Main run loop; processes input queue.
"""
while not Thread.aborted():
message = self.queue.get()
if message == Worker.HALT:
self.queue.put(message)
return
call = message
try:
call()
except Exception:
log.exception(str(call))
示例11: run
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def run(self):
"""
Read the pending queue and dispatch requests
to the plugin thread pool.
"""
while not Thread.aborted():
request = self.pending.get()
try:
pending = self.pending
plugin = self.select_plugin(request)
transaction = Transaction(plugin, pending, request)
task = Task(transaction)
plugin.pool.run(task)
except Exception:
self.pending.commit(request.sn)
log.exception(request.sn)
示例12: run
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def run(self):
"""
Main run loop; processes input queue.
"""
while not Thread.aborted():
call = self.queue.get()
if call == 1:
# # busy
continue
if not call:
# termination requested
return
try:
call()
except Exception:
log.exception(utf8(call))
示例13: _fn
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def _fn(thing, *args, **kwargs):
repair = lambda: None
while not Thread.aborted():
try:
repair()
return fn(thing, *args, **kwargs)
except _NotFound as e:
raise NotFound(*e.args)
except LinkError as le:
log.warning(str(le))
repair = thing.repair
sleep(DELAY)
except ConnectionError as pe:
log.warning(str(pe))
repair = thing.repair
sleep(DELAY)
示例14: _fn
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def _fn(messenger, *args, **kwargs):
repair = lambda: None
while not Thread.aborted():
try:
repair()
return fn(messenger, *args, **kwargs)
except ChannelError, le:
if le.code != 404:
log.error(utf8(le))
repair = messenger.repair
sleep(DELAY)
else:
raise NotFound(*le.args)
except CONNECTION_EXCEPTIONS, pe:
log.error(utf8(pe))
repair = messenger.repair
sleep(DELAY)
示例15: get_reply
# 需要导入模块: from gofer.common import Thread [as 别名]
# 或者: from gofer.common.Thread import aborted [as 别名]
def get_reply(self, sn, reader):
"""
Get the reply matched by serial number.
:param sn: The request serial number.
:type sn: str
:param reader: A reader.
:type reader: gofer.messaging.consumer.Reader
:return: The matched reply document.
:rtype: Document
"""
timer = Timer()
timeout = float(self.wait)
while not Thread.aborted():
timer.start()
document = reader.search(sn, int(timeout))
timer.stop()
elapsed = timer.duration()
if elapsed > timeout:
raise RequestTimeout(sn, self.wait)
else:
timeout -= elapsed
if not document:
raise RequestTimeout(sn, self.wait)
# rejected
if document.status == 'rejected':
raise DocumentError(
document.code,
document.description,
document.document,
document.details)
# accepted | started
if document.status in ('accepted', 'started'):
continue
# progress reported
if document.status == 'progress':
self.on_progress(document)
continue
# reply
return self.on_reply(document)