本文整理汇总了Python中Pyro4.naming方法的典型用法代码示例。如果您正苦于以下问题:Python Pyro4.naming方法的具体用法?Python Pyro4.naming怎么用?Python Pyro4.naming使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pyro4
的用法示例。
在下文中一共展示了Pyro4.naming方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getNS
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import naming [as 别名]
def getNS():
"""
Return a Pyro name server proxy. If there is no name server running,
start one on 0.0.0.0 (all interfaces), as a background process.
"""
import Pyro4
try:
return Pyro4.locateNS()
except Pyro4.errors.NamingError:
logger.info("Pyro name server not found; starting a new one")
os.system("python -m Pyro4.naming -n 0.0.0.0 &")
# TODO: spawn a proper daemon ala http://code.activestate.com/recipes/278731/ ?
# like this, if there's an error somewhere, we'll never know... (and the loop
# below will block). And it probably doesn't work on windows, either.
while True:
try:
return Pyro4.locateNS()
except:
pass
示例2: getNS
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import naming [as 别名]
def getNS():
"""
Return a Pyro name server proxy. If there is no name server running,
start one on 0.0.0.0 (all interfaces), as a background process.
"""
import Pyro4
try:
return Pyro4.locateNS()
except Pyro4.errors.NamingError:
logger.info("Pyro name server not found; starting a new one")
os.system("python -m Pyro4.naming -n 0.0.0.0 &")
# TODO: spawn a proper daemon ala http://code.activestate.com/recipes/278731/ ?
# like this, if there's an error somewhere, we'll never know... (and the loop
# below will block). And it probably doesn't work on windows, either.
while True:
try:
return Pyro4.locateNS()
except:
pass
示例3: get_my_ip
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import naming [as 别名]
def get_my_ip():
"""
Try to obtain our external ip (from the pyro nameserver's point of view)
This tries to sidestep the issue of bogus `/etc/hosts` entries and other
local misconfigurations, which often mess up hostname resolution.
If all else fails, fall back to simple `socket.gethostbyname()` lookup.
"""
import socket
try:
import Pyro4
# we know the nameserver must exist, so use it as our anchor point
ns = Pyro4.naming.locateNS()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((ns._pyroUri.host, ns._pyroUri.port))
result, port = s.getsockname()
except:
try:
# see what ifconfig says about our default interface
import commands
result = commands.getoutput("ifconfig").split("\n")[1].split()[1][5:]
if len(result.split('.')) != 4:
raise Exception()
except:
# give up, leave the resolution to gethostbyname
result = socket.gethostbyname(socket.gethostname())
return result
示例4: start_local_nameserver
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import naming [as 别名]
def start_local_nameserver(host=None, port=0, nic_name=None):
"""
starts a Pyro4 nameserver in a daemon thread
Parameters:
-----------
host: str
the hostname to use for the nameserver
port: int
the port to be used. Default =0 means a random port
nic_name: str
name of the network interface to use
Returns:
--------
tuple (str, int):
the host name and the used port
"""
if host is None:
if nic_name is None:
host = 'localhost'
else:
host = nic_name_to_host(nic_name)
uri, ns, _ = Pyro4.naming.startNS(host=host, port=port)
host, port = ns.locationStr.split(':')
thread = threading.Thread(target=ns.requestLoop, name='Pyro4 nameserver started by HpBandSter')
thread.daemon=True
thread.start()
return(host, int(port))
示例5: run
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import naming [as 别名]
def run(self):
"""
Begin execution of the name server process and start the main loop.
"""
self._base = cloudpickle.loads(self._base)
try:
Pyro4.naming.NameServer = self._base
self._daemon = Pyro4.naming.NameServerDaemon(self.host, self.port)
except Exception:
self._queue.put(format_exception())
return
self._queue.put('STARTED')
self._uri = self._daemon.uriFor(self._daemon.nameserver)
self.host = self._uri.host
self.port = self._uri.port
self.addr = SocketAddress(self.host, self.port)
internal_uri = self._daemon.uriFor(self._daemon.nameserver, nat=False)
bcserver = None
hostip = self._daemon.sock.getsockname()[0]
# Start broadcast responder
bcserver = BroadcastServer(internal_uri)
sys.stdout.write(
'Broadcast server running on %s\n' % bcserver.locationStr
)
sys.stdout.flush()
bcserver.runInThread()
sys.stdout.write(
'NS running on %s (%s)\n' % (self._daemon.locationStr, hostip)
)
sys.stdout.write('URI = %s\n' % self._uri)
sys.stdout.flush()
try:
self._daemon.requestLoop(lambda: not self._shutdown_event.is_set())
finally:
self._daemon.close()
if bcserver is not None:
bcserver.close()
sys.stdout.write('NS shut down.\n')
sys.stdout.flush()
示例6: get_my_ip
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import naming [as 别名]
def get_my_ip():
"""
Try to obtain our external ip (from the pyro nameserver's point of view)
This tries to sidestep the issue of bogus `/etc/hosts` entries and other
local misconfigurations, which often mess up hostname resolution.
If all else fails, fall back to simple `socket.gethostbyname()` lookup.
"""
import socket
try:
import Pyro4
# we know the nameserver must exist, so use it as our anchor point
ns = Pyro4.naming.locateNS()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((ns._pyroUri.host, ns._pyroUri.port))
result, port = s.getsockname()
except:
try:
# see what ifconfig says about our default interface
import commands
result = commands.getoutput("ifconfig").split("\n")[1].split()[1][5:]
if len(result.split('.')) != 4:
raise Exception()
except:
# give up, leave the resolution to gethostbyname
result = socket.gethostbyname(socket.gethostname())
return result