当前位置: 首页>>代码示例>>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;未经允许,请勿转载。