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


Python connection.Client方法代碼示例

本文整理匯總了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 
開發者ID:sdn-ixp,項目名稱:iSDX,代碼行數:25,代碼來源:policy_loader.py

示例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() 
開發者ID:sdn-ixp,項目名稱:iSDX,代碼行數:25,代碼來源:lib.py

示例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 
開發者ID:sdn-ixp,項目名稱:iSDX,代碼行數:26,代碼來源:tmgr.py

示例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) 
開發者ID:zim-desktop-wiki,項目名稱:zim-desktop-wiki,代碼行數:24,代碼來源:ipc.py

示例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 
開發者ID:sdn-ixp,項目名稱:iSDX,代碼行數:13,代碼來源:arproxy.py

示例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`
# 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:reduction.py

示例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 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:managers.py

示例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 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:managers.py

示例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") 
開發者ID:singe,項目名稱:container-breakouts,代碼行數:9,代碼來源:worker.py

示例10: connect

# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import Client [as 別名]
def connect(self):
        sock = Client(self.address, 'AF_UNIX')
        return sock 
開發者ID:RUB-SysSec,項目名稱:grimoire,代碼行數:5,代碼來源:communicator.py

示例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) 
開發者ID:kwikteam,項目名稱:klustakwik2,代碼行數:8,代碼來源:monitoring.py

示例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) 
開發者ID:ActiveState,項目名稱:code,代碼行數:9,代碼來源:recipe-578260.py

示例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() 
開發者ID:ActiveState,項目名稱:code,代碼行數:12,代碼來源:recipe-578260.py

示例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() 
開發者ID:ElevenPaths,項目名稱:uac-a-mola,代碼行數:6,代碼來源:agent.py

示例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) 
開發者ID:gsastry,項目名稱:human-rl,代碼行數:29,代碼來源:frame.py


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