本文整理汇总了Python中pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher.jobFinished方法的典型用法代码示例。如果您正苦于以下问题:Python AsyncoreDispatcher.jobFinished方法的具体用法?Python AsyncoreDispatcher.jobFinished怎么用?Python AsyncoreDispatcher.jobFinished使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher
的用法示例。
在下文中一共展示了AsyncoreDispatcher.jobFinished方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SNMPPDUHarness
# 需要导入模块: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 别名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import jobFinished [as 别名]
class SNMPPDUHarness(threading.Thread):
def __init__(self, pdu, listen_address, listen_port, community="public"):
super(SNMPPDUHarness, self).__init__()
self.logger = logging.getLogger(__name__)
self.pdu = pdu
self.snmp_handler = SNMPPDUHandler(self.pdu, community=community)
self.listen_address = listen_address
self.listen_port = listen_port
self.transportDispatcher = AsyncoreDispatcher()
self._lock = threading.Lock()
self._stop_requested = False
def run(self):
with self._lock:
if self._stop_requested:
return
self.logger.info("Starting PDU '{}' on {}:{}".format(
self.pdu.name, self.listen_address, self.listen_port)
)
self.transportDispatcher.registerRecvCbFun(
self.snmp_handler.message_handler)
# UDP/IPv4
self.transportDispatcher.registerTransport(
udp.domainName,
udp.UdpSocketTransport().openServerMode(
(self.listen_address, self.listen_port))
)
self.transportDispatcher.jobStarted(1)
try:
# Dispatcher will never finish as job#1 never reaches zero
self.transportDispatcher.runDispatcher()
except Exception:
self.transportDispatcher.closeDispatcher()
def stop(self):
with self._lock:
self._stop_requested = True
try:
self.transportDispatcher.jobFinished(1)
except KeyError:
pass # The job is not started yet and will not start