當前位置: 首頁>>代碼示例>>Python>>正文


Python AsyncoreDispatcher.jobFinished方法代碼示例

本文整理匯總了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
開發者ID:internap,項目名稱:virtualpdu,代碼行數:51,代碼來源:pysnmp_handler.py


注:本文中的pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher.jobFinished方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。