本文整理匯總了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