当前位置: 首页>>代码示例>>Python>>正文


Python Client.recv方法代码示例

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


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

示例1: __init__

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
class UIListener:
    def __init__(self, address, port, authkey):
        self.client = Client((address, port), authkey=authkey)

    def get_args(self, n):
        return [self.client.recv() if self.client.poll(0.5) else None for _ in range(n)]

    def listenloop(self):
        keepalive = True

        try:
            while keepalive:
                while self.client.poll():
                    data = self.client.recv()
                    print('{}: {}'.format('x64' if utils.is64bit() else 'x86', data))

                    if data == 'close':
                        keepalive = False
                    else:
                        func = _interface[data]
                        self.client.send(func(*self.get_args(func.__code__.co_argcount)))
                        print('{}: sent response to {}'.format('x64' if utils.is64bit() else 'x86', data))

                time.sleep(0.05)
        except EOFError or ConnectionError:
            pass

            self.client.close()
开发者ID:TehVulpes,项目名称:WinAutomate,代码行数:30,代码来源:uilistener.py

示例2: Worker

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
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,代码行数:27,代码来源:distproc.py

示例3: DBClient

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
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,代码行数:27,代码来源:ramDB_c.py

示例4: LockOutputFrequency

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
class LockOutputFrequency(ExternalParameterBase):

    className = "Digital Lock Output Frequency"
    _outputChannels = {"OutputFrequency": "MHz", "Harmonic": ""}

    def __init__(self, name, config, globalDict, instrument="localhost:16888"):
        logger = logging.getLogger(__name__)
        ExternalParameterBase.__init__(self, name, config, globalDict)
        logger.info( "trying to open '{0}'".format(instrument) )
        host, port = instrument.split(':')
        self.instrument = Client((host, int(port)), authkey=b"yb171")
        logger.info( "opened {0}".format(instrument) )
        self.setDefaults()
        self.initializeChannelsToExternals()
        
    def setValue(self, channel, v):
        self.instrument.send( ('set{0}'.format(channel), (v, ) ) )
        result = self.instrument.recv()
        if isinstance(result, Exception):
            raise result
        return result
        
    def getValue(self, channel):
        self.instrument.send( ('get{0}'.format(channel), tuple() ) )
        result = self.instrument.recv()
        if isinstance(result, Exception):
            raise result
        return result
        
    def close(self):
        del self.instrument
开发者ID:pyIonControl,项目名称:IonControl,代码行数:33,代码来源:InterProcessParameters.py

示例5: triggerEvent

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
def triggerEvent( type, scheduleMethod, *args ):
    """
    This function inserts an event into CHOTestMonkey
    """
    host = "localhost"
    port = 6000
    address = ( host, port )
    conn = Client( address )
    request = []
    request.append( 1 )
    request.append( type )
    request.append( scheduleMethod )
    for arg in args:
        request.append( arg )
    conn.send( request )
    response = conn.recv()
    while response == 11:
        conn.close()
        time.sleep( 1 )
        conn = Client( address )
        conn.send( request )
        response = conn.recv()
    if response == 10:
        print "Event inserted:", type, scheduleMethod, args
    elif response == 20:
        print "Unknown message to server"
    elif response == 21:
        print "Unknown event type to server"
    elif response == 22:
        print "Unknown schedule method to server"
    elif response == 23:
        print "Not enough argument"
    else:
        print "Unknown response from server:", response
    conn.close()
开发者ID:opennetworkinglab,项目名称:OnosSystemTest,代码行数:37,代码来源:EventTrigger.py

示例6: ThreadedExponentClient

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
class ThreadedExponentClient(ExponentClient):
    def __init__(self, ip, port, password):
        super(ThreadedExponentClient, self).__init__(ip, port, password)

        self.conn = Client((self.ip, self.port))

    def _auth(self, password):
        self.conn.send(password)
        auth_value = self.conn.recv()

        if auth_value == 'AUTH':
            print("Authorized")
            return True
        else:
            raise RuntimeError("Invalid Password")
            return False

    def __del__(self):
        print("Entering del")
        if self.__dict__.get('conn') != None:
            self.conn.close()

    def send(self, value):
        self.conn.send(value)
        return self.conn.recv()
开发者ID:cylussec,项目名称:pythonserver,代码行数:27,代码来源:client.py

示例7: send_update

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
 def send_update(self, id, route):
     # TODO: Explore what is better, persistent client sockets or
     # new socket for each BGP update
     "Send this BGP route to participant id's controller"
     logger.debug("Sending a route update to participant "+str(id))
     conn = Client(tuple(self.participants[id].eh_socket), authkey = None)
     conn.send(json.dumps({'bgp': route}))
     conn.recv()
     conn.close()
开发者ID:ckannan,项目名称:iSDX,代码行数:11,代码来源:route_server.py

示例8: do_conn

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
 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,代码行数:12,代码来源:cli.py

示例9: CliClient

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
class CliClient(cmd.Cmd):

    def __init__(self,address,id):
        self.id = id
        self.connection = Client(address, authkey='secret password')
        cmd.Cmd.__init__(self)

    def onecmd(self,line):
        self.connection.send(("creator",line))
        while self.connection.poll(0.1):
            print self.connection.recv()        
开发者ID:benthomasson,项目名称:pymud,代码行数:13,代码来源:cliclient.py

示例10: conn

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
 def conn(self, serveur=None):
     address = (params['SERVEUR'], params['PORT'])
     print "Connecting : ", address
     print "Params = ", params
     try:
         conn = Client(address, authkey=params['PASSWORD'])
         print "Connexion etablie"
         ## Reception de l'invite du serveur
         print conn.recv()
         return conn
     except:
         print "Erreur connexion"
         return None
开发者ID:chrislyon,项目名称:my-ordo-project,代码行数:15,代码来源:cli_sav.py

示例11: workerConnection

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
    def workerConnection(self, wid):
        """Thread with worker connection"""
        worker = self.workers[wid]
        self.called += 1
        if self.verboseLog:
            print "[INFO] Connecting to %s:%d..." % (worker.ipaddress, worker.port)
        #TODO make try except statement to catch unresponsive hosts
        address = (worker.ipaddress, worker.port)
        try:
            conn = Client(address, authkey=worker.password)
            worker.alive = True # Add a good flag
            
            # Connect and get ready token
            resp = conn.recv()
            
            if self.verboseLog:
                print resp[0]
        
            worker.corecount = resp[1]
            self.C.append(resp[1]) # Add the number of available cores to collection

            with open("job.tar.gz", 'rb') as f:
                conn.send_bytes(f.read())
            f.close()
        
            # PAUSE HERE and wait for all threads to return core number
            self.wait_for_core_count.wait()
        
            print "[INFO] %d Job files allocated to worker %s" % (len(worker.jobFiles), worker.ipaddress)
        
            rec = conn.recv()
            if self.verboseLog:
                print rec[0]

            conn.send([self.inputJob[0], {"input" : worker.jobFiles, "joboptions" : self.joboptions}])
 
            output = conn.recv()
            if output[0]:
                self.output.append(output[0]) #Write to stack of histograms
                self.success += 1
            else:
                print "[ERROR] Job failed at %s:%d" % address
                # TODO We should resubmit the jobs to another worker....
            conn.close()
            print "[INFO] Connection to %s closed." % worker.ipaddress

        except:
            print "[WARNING] Connection to %s:%d failed." % (address[0], address[1])#, sys.exc_info()[1][1])
        finally:
            self.alive -= 1
开发者ID:mdj,项目名称:GluinoAnalysis,代码行数:52,代码来源:JobHandlerDist.py

示例12: ProcClient

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
class ProcClient(threading.Thread):
    def __init__(self, addr, authkey):
        threading.Thread.__init__(self)
        self.bus = None
        self.addr = addr
        self.authkey = authkey
        self.conn = None
        self.running = False

        self.setDaemon(True)

    def run(self):
        self.conn = None
        for i in range(0, 3):
            self.bus.log("Starting process client connection to: %s:%d" % self.addr)
            try:
                self.conn = Client(self.addr, authkey=self.authkey)
                break
            except:
                self.bus.log("", traceback=True)
                time.sleep(10.0)

        if not self.conn:
            self.bus.log("Failed to connect to %s:%d" % self.addr)
            return

        self.running = True
        while self.running:
            try:
                if self.conn.poll(1.0):
                    print self.conn.recv()
            except IOError:
                self.stop()
                break

    def stop(self):
        if not self.running:
            return

        self.bus.log("Stopping process client connection")
        if self.conn:
            self.running = False
            self.conn.close()
            self.conn = None

    def send(self, data):
        self.conn.send(data)

    def recv(self):
        return self.conn.recv()
开发者ID:pombredanne,项目名称:conductor,代码行数:52,代码来源:connection.py

示例13: get_json

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
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,代码行数:31,代码来源:http_status.py

示例14: process_data2

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
 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,代码行数:9,代码来源:reciever.py

示例15: call

# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import recv [as 别名]
        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,代码行数:28,代码来源:ipc.py


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