本文整理汇总了Python中multiprocessing.connection.Client.close方法的典型用法代码示例。如果您正苦于以下问题:Python Client.close方法的具体用法?Python Client.close怎么用?Python Client.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.connection.Client
的用法示例。
在下文中一共展示了Client.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: communicate
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
def communicate(message):
address = ('localhost',6345)
conn = Client(address)
conn.send(message)
reply = conn.recv()
conn.close()
return reply
示例2: __enter__
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
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()
示例3: __init__
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [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()
示例4: ThreadedExponentClient
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [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()
示例5: shutdown_metric
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
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]) + '.')
示例6: send
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
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()
示例7: import_exec_globals
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
def import_exec_globals(config, session):
'''
get exec_globals directory
cycle over its files
if the file name not in importregistry
send its contents to server
put filename in importregistry
'''
for module in get_plugins(config):
dirname = os.path.join(os.path.dirname(module.__file__),
'exec_globals')
for fname in sorted(os.listdir(dirname)):
if fname.endswith('.py'):
name = 'execs:' + fname[:-3]
try:
session.query(ImportRegistry).filter(ImportRegistry.name==name).one()
except NoResultFound:
path = os.path.join(dirname, fname)
with open(path, 'r') as f:
eg = f.read()
kb = Client((config('kb_host'), int(config('kb_port'))))
kb.send_bytes('compiler:exec_globals:' + eg)
kb.send_bytes('FINISH-TERMS')
for fact in iter(kb.recv_bytes, 'END'):
print(fact)
kb.close()
ir = ImportRegistry(name)
session.add(ir)
示例8: send
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [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.
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()
示例9: triggerEvent
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [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()
示例10: ConnectClient
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
class ConnectClient():
address = None
conn = None
def __init__(self, ip = 'localhost', port = 7000):
self.address = (ip, port)
self.conn = Client(self.address)
def __del__(self):
self.conn.close()
def register_module(self, process_file):
"""send and register a module in the server"""
f = open(process_file, "rb")
l = f.read()
self.conn.send([0, l])
f.close()
def request_process(self, args):
"""request the server to do a process previously sent in a module"""
self.conn.send([1, args[0]] + args[1:])
answer = self.conn.recv()
if isinstance(answer, Exception):
raise answer
return answer
示例11: send
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
def send(self, packet):
address = ('localhost', self.port)
conn = Client(address, authkey=self.pwd)
self._printDebug("MultiBus,Client: send")
conn.send(packet)
conn.send('close')
conn.close()
示例12: _send
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
def _send(self, msg):
conn = Client(self.address, authkey=self.authkey)
conn.send(msg)
result = conn.recv()
conn.close()
if result:
self._locked = True
return result
示例13: run
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
def run():
global connection
connection = Client(('localhost', 6000), authkey=b'bluesky')
plugin.init()
stack.init()
bs.sim.doWork()
connection.close()
print('Node', nodeid, 'stopped.')
示例14: run
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
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]
示例15: send
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import close [as 别名]
def send(self, msg):
try:
connection = Client(self.address, authkey=self.auth)
connection.send(msg)
connection.close()
except ConnectionRefusedError:
print('Connection Refused')