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


Python Pyro4.Daemon方法代碼示例

本文整理匯總了Python中Pyro4.Daemon方法的典型用法代碼示例。如果您正苦於以下問題:Python Pyro4.Daemon方法的具體用法?Python Pyro4.Daemon怎麽用?Python Pyro4.Daemon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Pyro4的用法示例。


在下文中一共展示了Pyro4.Daemon方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pyro_daemon

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import Daemon [as 別名]
def pyro_daemon(name, obj, random_suffix=False, ip=None, port=None):
    """
    Register object with name server (starting the name server if not running
    yet) and block until the daemon is terminated. The object is registered under
    `name`, or `name`+ some random suffix if `random_suffix` is set.

    """
    if random_suffix:
        name += '.' + hex(random.randint(0, 0xffffff))[2:]
    import Pyro4
    with getNS() as ns:
        with Pyro4.Daemon(ip or get_my_ip(), port or 0) as daemon:
            # register server for remote access
            uri = daemon.register(obj, name)
            ns.remove(name)
            ns.register(name, uri)
            logger.info("%s registered with nameserver (URI '%s')" % (name, uri))
            daemon.requestLoop() 
開發者ID:loretoparisi,項目名稱:word2vec-twitter,代碼行數:20,代碼來源:word2vecReaderUtils.py

示例2: pyro_daemon

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import Daemon [as 別名]
def pyro_daemon(name, obj, random_suffix=False, ip=None, port=None):
    """
    Register object with name server (starting the name server if not running
    yet) and block until the daemon is terminated. The object is registered under
    `name`, or `name`+ some random suffix if `random_suffix` is set.

    """
    if random_suffix:
        name += '.' + hex(random.randint(0, 0xffffff))[2:]
    import Pyro4

    with getNS() as ns:
        with Pyro4.Daemon(ip or get_my_ip(), port or 0) as daemon:
            # register server for remote access
            uri = daemon.register(obj, name)
            ns.remove(name)
            ns.register(name, uri)
            logger.info("%s registered with nameserver (URI '%s')" % (name, uri))
            daemon.requestLoop() 
開發者ID:masr,項目名稱:pynlpini,代碼行數:21,代碼來源:utils.py

示例3: test_compat_layer

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import Daemon [as 別名]
def test_compat_layer():
    from Pyro4 import naming
    from Pyro4 import socketutil
    from Pyro4 import util
    try:
        _ = 1//0
    except ZeroDivisionError:
        tb = util.getPyroTraceback()
        assert len(tb) == 3
        assert "Traceback" in tb[0]
        assert "zero" in tb[2]
    assert 4 == socketutil.getIpVersion("127.0.0.1")
    assert 6 == socketutil.getIpVersion("::1")
    Pyro4.URI("PYRO:test@localhost:5555")
    p = Pyro4.Proxy("PYRO:test@localhost:5555")
    Pyro4.BatchProxy(p)
    Pyro4.Daemon()
    assert socketutil.getIpAddress("localhost", ipVersion=4).startswith("127.0")
    if socket.has_ipv6:
        try:
            assert ":" in socketutil.getIpAddress("localhost", ipVersion=6)
        except socket.error as x:
            if str(x) != "unable to determine IPV6 address":
                raise
    assert "127.0.0.1" == socketutil.getIpAddress("127.0.0.1")
    assert "::1" == socketutil.getIpAddress("::1")
    assert "127.0.0.1" == socketutil.getInterfaceAddress("127.0.0.1")
    with pytest.raises(NotImplementedError):
        naming.NameServer()
    with pytest.raises(NotImplementedError):
        _ = p._pyroHmacKey
    with pytest.raises(NotImplementedError):
        p._pyroHmacKey = b"fail" 
開發者ID:irmen,項目名稱:Pyro5,代碼行數:35,代碼來源:test_pyro4compat.py

示例4: register_server

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import Daemon [as 別名]
def register_server(serverobject, host=None, port=0, unixsocket=None, nathost=None, natport=None):
    """Regiseter the server with Pycopia asyncio event handler."""
    host = host or Pyro4.config.HOST or Pyro4.socketutil.getIpAddress(socket.getfqdn())
    pyrodaemon = Pyro4.Daemon(host=host, port=port,
            unixsocket=unixsocket, nathost=nathost, natport=natport)
    uri = pyrodaemon.register(serverobject)
    ns=Pyro4.locateNS()
    ns.register("{}:{}".format(serverobject.__class__.__name__, socket.getfqdn()), uri)
    p = PyroAsyncAdapter(pyrodaemon)
    asyncio.poller.register(p)
    return p 
開發者ID:kdart,項目名稱:pycopia,代碼行數:13,代碼來源:pyro.py

示例5: start

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import Daemon [as 別名]
def start(self, *args, **kwargs):
        """Start the Pyro daemon."""
        Pyro4.current_context.STARTUP_PERIOD = False
        Syslogger.logger().debug('Authentication enabled')
        Syslogger.logger().debug('Obtaining lock')
        with DaemonLock.LOCK:
            Syslogger.logger().debug('Obtained lock')
            Syslogger.logger().debug('Starting daemon request loop')
            RpcNSMixinDaemon.DAEMON.requestLoop(*args, **kwargs)
        Syslogger.logger().debug('Daemon request loop finished') 
開發者ID:ITDevLtd,項目名稱:MCVirt,代碼行數:12,代碼來源:rpc_daemon.py

示例6: shutdown

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import Daemon [as 別名]
def shutdown(self, signum, frame):
        """Shutdown Pyro Daemon."""
        Syslogger.logger().error('Received signal: %s' % signum)
        for timer in self.timer_objects:
            Syslogger.logger().info('Shutting down timer: %s' % timer)
            try:
                timer.cancel()
            except Exception:
                pass
        RpcNSMixinDaemon.DAEMON.shutdown()
        Syslogger.logger().debug('finisehd shutdown') 
開發者ID:ITDevLtd,項目名稱:MCVirt,代碼行數:13,代碼來源:rpc_daemon.py

示例7: __init__

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import Daemon [as 別名]
def __init__(self, scan=True, use_pyro_ns=False, bind_localhost=False):
        self.mdb = MusicFileDatabase(scan_changes=scan)
        host = "localhost" if bind_localhost else Pyro4.socketutil.getIpAddress(None, workaround127=True)
        self.pyro_daemon = Pyro4.Daemon(host=host, port=0 if use_pyro_ns else BACKEND_PORT)
        self.pyro_uri = self.pyro_daemon.register(JukeboxBackendRemoting, "jukebox.backend")
        if use_pyro_ns:
            with Pyro4.locateNS() as ns:
                ns.register("jukebox.backend", self.pyro_uri)
        self.cli = JukeboxBackendCli(self.mdb, self.pyro_uri) 
開發者ID:irmen,項目名稱:synthesizer,代碼行數:11,代碼來源:backend.py

示例8: run

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import Daemon [as 別名]
def run(self):
        """
        Begin execution of the agent process and start the main loop.
        """
        # Capture SIGINT
        signal.signal(signal.SIGINT, self._sigint_handler)

        try:
            ns = NSProxy(self.nsaddr)
            self._daemon = Pyro4.Daemon(self._host, self.port)
            self.base = cloudpickle.loads(self.base)
            self.agent = self.base(
                name=self.name,
                host=self._host,
                serializer=self._serializer,
                transport=self._transport,
                attributes=self.attributes,
            )
        except Exception:
            self._queue.put(format_exception())
            return

        self.name = self.agent.name
        uri = self._daemon.register(self.agent)
        try:
            ns.register(self.name, uri, safe=True)
        except Pyro4.errors.NamingError:
            self._queue.put(format_exception())
            return
        finally:
            ns.release()

        self._queue.put('STARTED:' + self.name)

        self._daemon.requestLoop(lambda: not self._shutdown_event.is_set())
        self._daemon.unregister(self.agent)

        self._teardown() 
開發者ID:opensistemas-hub,項目名稱:osbrain,代碼行數:40,代碼來源:agent.py

示例9: startServer

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import Daemon [as 別名]
def startServer():
    server = Server()
    # make a Pyro daemon
    daemon = Pyro4.Daemon()             
    # locate the name server running
    ns = Pyro4.locateNS()
    # register the server as a Pyro object
    uri = daemon.register(server)  
    # register the object with a name in the name server
    ns.register("server", uri)   
    # print the uri so we can use it in the client later
    print("Ready. Object uri =", uri)
    # start the event loop of the server to wait for calls
    daemon.requestLoop() 
開發者ID:PacktPublishing,項目名稱:Python-Parallel-Programming-Cookbook-Second-Edition,代碼行數:16,代碼來源:pyro_server.py


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