• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python connection.Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中multiprocessing.connection.Client的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: start

    def start(self, port=8080):
        """
        Starts the server. This will actually start the child process.

        :param port: Local TCP/IP port to which the underlying socket is
                     connected to.
        """
        self.__process = multiprocessing.Process(target=childProcess,
                                                 name=self.__name,
                                                 args=(port, ))
        self.__process.start()
        self.__running = False
        try:
            if sys.platform == "win32":
                self._client = Client(('localhost', port))
            else:
                try:
                    self._client = Client(('', port))
                except OSError:
                    # wait a second before starting, this occur if we were connected to
                    # previously running server that has just closed (we need to wait a
                    # little before starting a new one)
                    time.sleep(1)
                    self._client = Client(('', port))
            logger.info("Connected to Code Completion Server on 127.0.0.1:%d" %
                        port)
            self.__running = True
            self._lock = thread.allocate_lock()
            thread.start_new_thread(self._threadFct, ())
        except OSError:
            logger.exception("Failed to connect to Code Completion Server on "
                             "127.0.0.1:%d" % port)
        return self.__running
开发者ID:ogranada,项目名称:pyqode.core,代码行数:33,代码来源:system.py


示例2: DBClient

class DBClient(object):
	def __init__(self, address=('localhost',6000), authkey='difficult password'):
		self.conn = Client(address, authkey=authkey)

	def get_batch(self, elements):
		self.conn.send(list(elements))
		to_ret = self.conn.recv()
		return to_ret

	def get(self, element):
		self.conn.send(element)
		to_ret = self.conn.recv()
		return to_ret

	def set(self, key, val):
		self.conn.send({key: val})

	def set_batch(self, key_val_dict):
		self.conn.send(key_val_dict)

	def __getitem__(self, key):
		return self.get(key)

	def __setitem__(self, key, val):
		self.set(key, val)
开发者ID:d1ma,项目名称:light_ramdb,代码行数:25,代码来源:ramDB_c.py


示例3: send

    def send(self, msg):
        #conn = Client((self.address, self.port), authkey=str(self.key))
        conn = Client((self.address, self.port))

        conn.send(json.dumps(msg))

        conn.close()
开发者ID:chengguozhen,项目名称:iSDX,代码行数:7,代码来源:client.py


示例4: Worker

class Worker(object):

    def __init__(self, address, port, authkey=None):

        self.connection = Client((address, port), authkey=authkey)
        self.worker_id = self.connection.recv()

    def run(self):
        while True:

            task_data = self.connection.recv()
            if task_data is False:
                return

            result = self.do_task(task_data)
            self.connection.send((task_data, result))

    def log(self, *items):
        print "== Worker %s ==" % self.worker_id,
        for item in items:
            print item,
        print

    def do_task(self, data):
        raise NotImplementedError("A subclass must implement this.")
开发者ID:AmesianX,项目名称:des,代码行数:25,代码来源:distproc.py


示例5: get_json

def get_json():
    # Get the current values
    c = Client(("localhost", 25000))
    c.send("get")
    now = c.recv()

    # Now we parse all the data out of the results!
    data = {}
    data["IN_Temp"] = now.In_Temp
    data["IN_Humid"] = now.In_Humid
    data["OUT_Temp"] = now.Out_Temp
    data["OUT_Humid"] = now.Out_Humid
    data["Out_Wind_Now"] = now.Out_Wind_Now
    data["OUT_Wind_Avg"] = now.Out_Wind_Avg
    data["OUT_Wind_Max"] = now.Out_Wind_Max
    data["OUT_Rain_Today"] = now.Out_Rain_Today
    data["OUT_Rain_Last_24h"] = now.Out_Rain_Last_24h
    data["OUT_Rain_Since_Reset"] = now.Out_Rain_Since_Reset
    data["ATTIC_Temp"] = now.Attic_Temp
    data["ATTIC_Humid"] = now.Attic_Humid
    data["NOW_URL"] = now.Now_URL
    data["NOW_Feel"] = now.Now_Feel
    data["NOW_Feel_High"] = now.Now_Feel_High
    data["NOW_Feel_Low"] = now.NOW_Feel_Low
    data["SYSTEM_CPU"] = now.System_CPU
    data["SYSTEM_RAM"] = now.System_RAM

    # Now return the json as a string
    return json.dumps(data)
开发者ID:1n5aN1aC,项目名称:rainmeter-pi,代码行数:29,代码来源:http_status.py


示例6: process_data2

 def process_data2(self, q):
     conn = Client(address, authkey="secret password")
     message = ""
     while True:
         message = conn.recv()
         # print "received", message[0],message[1]
         q.put(message)
开发者ID:IlluminatiNITW,项目名称:AlmabaseNewsScrapper,代码行数:7,代码来源:reciever.py


示例7: start_server

 def start_server(self, address, password):
     print("server waiting")
     listener = Listener()
     client = Client(address)
     client.send(listener.address)
     self._start_listener(listener)
     return listener.address
开发者ID:Benhgift,项目名称:note_study_tool,代码行数:7,代码来源:notebook.py


示例8: __enter__

class RsClient:

	def __enter__(self):
		"""no init"""

	def __exit__(self, type=None, value=None, tb=None):

		#self.conn may not exist so expect that it may fail.
		try:
			self.conn.close()
		except:
			pass

	def start(self, host='localhost', port=8000, key='8457#$%^&3648'):

		address = (host, port)
		self.conn = Client(address)

	def send(self, data):
		try:
			self.conn.send(data)
		except:
			self.stop()

	def stop(self):
		self.conn.close()
开发者ID:RhinoLance,项目名称:PythonProcessQueue,代码行数:26,代码来源:Communicator.py


示例9: shutdown_metric

def shutdown_metric(metric_server_addresses, authkey):
    """ This function tells all of the SimulationPotential instances running on the addresses in metric_server_addresses to shutdown. This is called when a SimulationClient instance shuts down.

    Args:
      metric_server_addresses: A list of tuples of the form (str, int) containing the hostnames and port numbers of the SimulationPotential instances.
      authkey (str): The password used in order to communicate with the SimulationPotential instances.

    Returns:
      float: The length of the curve with metric values in metric.

    """

    # For each SimulationPotential instance...
    for address in xrange(len(metric_server_addresses)):

        # Try making contact with the SimulationPotential instance...
        try:
            # Establish a connection with the SimulationPotential
            metric_server = Client(metric_server_addresses[address], authkey=authkey)

            # Send a status code indicating the SimulationPotential instance should stop running.
            metric_server.send({'status_code': comm_code('KILL')})

            # Close the connection.
            metric_server.close()

        # If contact with the SimulationPotential instance cannot be made then...
        except socket.error:
            # Make a note in the log which SimulationPotential couldn't be contacted.
            logging.warning('Failed to Make Connection to SimulationPotential at '
                          + str(metric_server_addresses[address]) + '.')
开发者ID:suttond,项目名称:MODOI,代码行数:31,代码来源:MetricValues.py


示例10: call

        def call(*args, **kwargs):
            global _recursive_conn_lock
            if _recursive_conn_lock:
                raise AssertionError, 'BUG: Recursive client connection'
                # Avoid hanging because we call the socket while the
                # server is blocking for our return value on the pipe.
                # If this is an issue blocking functionality,
                # re-route the call to the open pipe for which the
                # server is waiting.

            #~ if self._client_proxy_authkey is None:
                #~ self._client_proxy_authkey = AUTHKEY_FILE.raw()

            msg = RemoteMethodCall(self._obj, name, args, kwargs)
            logger.debug('Remote call from %i: %s', os.getpid(), msg)
            #~ print "CLIENT >>%s<<" % self._client_proxy_authkey
            #~ conn = Client(SERVER_ADDRESS, authkey=self._client_proxy_authkey)
            conn = Client(SERVER_ADDRESS, SERVER_ADDRESS_FAMILY)
            conn.send(msg)
            if not msg.async:
                re = conn.recv()
                logger.debug('Remote call returned to %i: %s', os.getpid(), re)
                if isinstance(re, Exception):
                    raise re
                else:
                    return re
开发者ID:DarioGT,项目名称:Zim-QDA,代码行数:26,代码来源:ipc.py


示例11: send

 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.
     if self.port == 5555:
         self.redis.rpush('flowqueue', msg)
     else:
         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
         self.logger.debug('PCTRLSEND ' + str(msg))
         conn.send(msg)
         self.logger.debug('TRYCONNCLOSE trying to close the connection in pctrl')
         conn.close()
开发者ID:jeroen92,项目名称:iSDX,代码行数:26,代码来源:lib.py


示例12: run

    def run(self):
        while not self._stop:
            address = ('localhost', 6000)
            conn = Client(address)
            msg = conn.recv()
            conn.close()

            [cb() for k,cb in self.cbs.items() if msg==k]
开发者ID:edne,项目名称:VimLiveHTML,代码行数:8,代码来源:browser.py


示例13: send

	def send(self, msg):

		try:
			connection = Client(self.address, authkey=self.auth)
			connection.send(msg)
			connection.close()
		except ConnectionRefusedError:
			print('Connection Refused')
开发者ID:OzymandiasTheGreat,项目名称:emoji-keyboard,代码行数:8,代码来源:emoji_lib.py


示例14: run

def run():
    global connection
    connection = Client(('localhost', 6000), authkey=b'bluesky')
    plugin.init()
    stack.init()
    bs.sim.doWork()
    connection.close()
    print('Node', nodeid, 'stopped.')
开发者ID:eman89,项目名称:bluesky,代码行数:8,代码来源:nodemanager.py


示例15: reset_rain

def reset_rain():
    # Reset rain_since_reset in the table
    # (╯°□°)╯︵ ┻━┻
    c = Client( ('localhost', 25000) )
    c.send("reset_rain")
    result = c.recv()
    
    return "reset!"
开发者ID:1n5aN1aC,项目名称:rainmeter-pi,代码行数:8,代码来源:http_reset_rain.py


示例16: RPCProxy

class RPCProxy(RPCObject):
    """
    RPCProxy, object running in child processes that connects to an :class:`RPCServer`
    object.
    """
    def __init__(self, address, authkey):
        super(RPCProxy, self).__init__()
        self._functions = { }
        self._quitnotifiers = set()
        self._conn = Client(address, authkey=authkey)
        self._conn.send(json.dumps({"name" : _mp.current_process().name, "pid" : os.getpid()}))
        self._should_exit = False
        self.register_function(self.exit_now, "exit")
        def _exit(*args):
            self.exit_now()
        signal.signal(signal.SIGINT, _exit)
        signal.signal(signal.SIGTERM, _exit)

    def listen(self):
        def handle_client(client_c):
            while not self._should_exit:
                try:
                    func_name, args, kwargs = client_c.recv()
                except EOFError:
                    self.exit_now()
                    break
                try:
                    r = self._functions[func_name](*args,**kwargs)
                    client_c.send(r)
                except Exception as e:
                    client_c.send(e)
        self.t = Thread(target=handle_client, args=(self._conn,))
        self.t.daemon = True
        self.t.start()

    def register_exit_notification(self, func):
        self._quitnotifiers.add(func)

    def remove_exit_notification(self, func):
        try:
            self._quitnotifiers.remove(func)
        except KeyError: pass

    def exit_now(self):
        log("Exit requested")
        self._should_exit = True
        for f in self._quitnotifiers:
            f()
        return True

    def should_exit(self):
        return self._should_exit

    def register_function(self, func, name = None):
        if name is None:
            name = func.__name__
        self._functions[name] = func
开发者ID:nEDM-TUM,项目名称:HimbeereCouch,代码行数:57,代码来源:rpc.py


示例17: run

 def run(self):
     address = ("localhost", 6000)
     conn = Client(address, authkey="secret password")
     while True:
         command = conn.recv_bytes()
         if command == "quit":
             break
         self.animations[:] = parse_command(command, self.boxs, "receiver")
     conn.close()
开发者ID:likang,项目名称:Reflekt,代码行数:9,代码来源:Reflekt.py


示例18: rebuild_handle

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
开发者ID:webiumsk,项目名称:WOT-0.9.15-CT,代码行数:10,代码来源:reduction.py


示例19: do_conn

 def do_conn(self,line):
     global conn
     address = (params['SERVEUR'], params['PORT'])
     try:
         conn = Client(address, authkey=params['PASSWORD'])
         print "Connexion etablie"
     except:
         print "Erreur connexion"
     ## Reception de l'invite du serveur
     print conn.recv()
开发者ID:chrislyon,项目名称:my-ordo-project,代码行数:10,代码来源:cli.py


示例20: __init__

 def __init__(self, portstr="/dev/m4_com", conn_type="serial"):
   self._pf = PacketFinder()
   self.conn_type = conn_type
   if self.conn_type == "serial":
     self._ser = serial.Serial(portstr, 115200, timeout=0)
     self._ser.flushInput()
   elif self.conn_type == "portal":
     conn = Client(address=('localhost', 50000), authkey='abracadabra')
     port = conn.recv()
     self.conn = Client(address=('localhost', port), authkey='abracadabra')
开发者ID:vincentwenxuan,项目名称:smores_document,代码行数:10,代码来源:serial_packet.py



注:本文中的multiprocessing.connection.Client类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python connection.Connection类代码示例发布时间:2022-05-27
下一篇:
Python multiprocessing.Value类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap