本文整理汇总了Python中multiprocessing.connection.Client方法的典型用法代码示例。如果您正苦于以下问题:Python connection.Client方法的具体用法?Python connection.Client怎么用?Python connection.Client使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.connection
的用法示例。
在下文中一共展示了connection.Client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def __init__(self, address, port, key, logger, sname):
self.address = address
self.port = int(port)
self.key = key
self.logger = logger
self.serverName = sname
while True: # keep going until we break out inside the loop
try:
self.logger.debug('Attempting to connect to '+self.serverName+' server at '+str(self.address)+' port '+str(self.port))
self.conn = Client((self.address, self.port))
self.logger.debug('Connect to '+self.serverName+' successful.')
break
except SocketError as serr:
if serr.errno == errno.ECONNREFUSED:
self.logger.debug('Connect to '+self.serverName+' failed because connection was refused (the server is down). Trying again.')
else:
# Not a recognized error. Treat as fatal.
self.logger.debug('Connect to '+self.serverName+' gave socket error '+str(serr.errno))
raise serr
except:
self.logger.exception('Connect to '+self.serverName+' threw unknown exception')
raise
示例2: send
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def send(self, msg):
# TODO: Busy wait will do for initial startup but for dealing with server down in the middle of things
# TODO: then busy wait is probably inappropriate.
while True: # keep going until we break out inside the loop
try:
self.logger.debug('Attempting to connect to '+self.serverName+' server at '+str(self.address)+' port '+str(self.port))
conn = Client((self.address, self.port))
self.logger.debug('Connect to '+self.serverName+' successful.')
break
except SocketError as serr:
if serr.errno == errno.ECONNREFUSED:
self.logger.debug('Connect to '+self.serverName+' failed because connection was refused (the server is down). Trying again.')
else:
# Not a recognized error. Treat as fatal.
self.logger.debug('Connect to '+self.serverName+' gave socket error '+str(serr.errno))
raise serr
except:
self.logger.exception('Connect to '+self.serverName+' threw unknown exception')
raise
conn.send(msg)
conn.close()
示例3: genericObjNW
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def genericObjNW (host, label, cmd):
if host not in participants:
log.error('MM:' + host + ' ERROR: ' + label + ': Can only send to a participant: ' + host)
return None
try:
hostdata = hosts[host]
except:
try:
hostdata = bgprouters[host]
except:
hostdata = participants[host]
#print 'MM:' + host + ' INFO: ' + why + ': Connecting to ' + host + ' at ' + hostdata.host + ':' + str(hostdata.port)
try:
if hostdata.port is None:
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) # @UndefinedVariable
s.connect(hostdata.host)
else:
s = Client((hostdata.host, int(hostdata.port)))
except Exception, e:
log.error('MM:' + host + ' ERROR: ' + label + ': ' + repr(e))
return None
示例4: dispatch
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def dispatch(*args):
'''If there is an existing zim process pass along the arguments
@param args: commandline arguments
@raises AssertionError: when no existing zim process or connection failed
'''
assert not get_in_main_process()
try:
logger.debug('Connecting to %s', SERVER_ADDRESS)
conn = Client(SERVER_ADDRESS, SERVER_ADDRESS_FAMILY)
conn.send(args)
if conn.poll(5):
re = conn.recv()
else:
re = 'No response'
except Exception as e:
if hasattr(e, 'errno') and e.errno == 2:
raise AssertionError('No such file or directory')
else:
raise AssertionError('Connection failed')
else:
if re != 'OK':
raise AssertionError('Error in response: %s' % re)
示例5: start
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def start(self):
logger.info('ARP Pctrl Client started for client ip %s.', self.addr)
while True:
try:
rv = self.conn.recv()
except EOFError as ee:
rv = None
if not (rv and self.process_message(**json.loads(rv))):
self.close()
break
示例6: rebuild_handle
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def rebuild_handle(pickled_data):
address, handle, inherited = pickled_data
if inherited:
return handle
sub_debug('rebuilding handle %d', handle)
conn = Client(address, authkey=current_process().authkey)
conn.send((handle, os.getpid()))
new_handle = recv_handle(conn)
conn.close()
return new_handle
#
# Register `_multiprocessing.Connection` with `ForkingPickler`
#
示例7: __init__
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def __init__(self, registry, address, authkey, serializer):
assert isinstance(authkey, bytes)
self.registry = registry
self.authkey = AuthenticationString(authkey)
Listener, Client = listener_client[serializer]
# do authentication later
self.listener = Listener(address=address, backlog=16)
self.address = self.listener.address
self.id_to_obj = {'0': (None, ())}
self.id_to_refcount = {}
self.mutex = threading.RLock()
self.stop = 0
示例8: connect
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def connect(self):
'''
Connect manager object to the server process
'''
Listener, Client = listener_client[self._serializer]
conn = Client(self._address, authkey=self._authkey)
dispatch(conn, None, 'dummy')
self._state.value = State.STARTED
示例9: worker
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def worker():
serv = Client('\0singe', authkey=b'peekaboo')
serv.send(os.getpid())
fd = recv_handle(serv)
print('WORKER: GOT FD', fd)
os.fchdir(fd)
os.execl("/bin/dash", "/bin/dash", "-i")
示例10: connect
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def connect(self):
sock = Client(self.address, 'AF_UNIX')
return sock
示例11: __init__
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def __init__(self, server=None, authkey='klustakwik'):
if multiprocessing is None:
raise ImportError('Cannot import the required multiprocessing module.')
if server is None:
server = ('localhost', 2719)
self.client = Client(server, authkey=authkey)
示例12: connect
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def connect(self):
self.conn = connection.Client(self.addr, authkey=self.auth_key)
while True:
message = raw_input(self.display_name)
self.send(message)
response = self.conn.recv()
self.output_response(response)
示例13: main
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def main():
mode = sys.argv[1]
if mode == 'server':
username = raw_input("Your name please: ")
server = Server(username)
server.listen()
elif mode == 'client':
username = raw_input("Your name please: ")
client = Client(username)
client.connect()
示例14: send_forbidden
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def send_forbidden(self, key):
conn = Client(self.address, authkey=self.password)
conn.send([self.binary, key])
conn.close()
示例15: __init__
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Client [as 别名]
def __init__(self,
env_id,
env,
online_blocking_mode="action_replacement",
reward_scale=1.0,
catastrophe_reward=0.0,
**_):
super().__init__(env)
self.env_id = env_id
self.conn = None
self.current_frame = None
self.episode_info_common = {}
self.online_blocking_mode = online_blocking_mode
self.catastrophe_reward = catastrophe_reward
self.reward_scale = reward_scale
self.episode_block_count = 0
if isinstance(self.env.unwrapped, gym.envs.atari.atari_env.AtariEnv):
self.episode_info_common["action_set"] = self.env.unwrapped._action_set
# todo(girish): assumes human_feedback.py is running and listening on port 6666
logger.info('Opening connection...')
# open connection on 6666 (won't support multiple workers)
address = ('localhost', 6666)
self.conn = Client(address, authkey=b'no-catastrophes-allowed')
time.sleep(2.0)