本文整理汇总了Python中multiprocessing.connection.Client.send_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python Client.send_bytes方法的具体用法?Python Client.send_bytes怎么用?Python Client.send_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.connection.Client
的用法示例。
在下文中一共展示了Client.send_bytes方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_exec_globals
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [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)
示例2: push_out
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [as 别名]
def push_out(self):
address = ('127.0.0.1', Spider.PUSH_OUT_PORT)
connection = Client(address, authkey=self.authkey)
log.info('Spider : connection established from {}'.format(address))
while True:
log.debug('in spider push_out')
url = self.pop_one()
if url:
try:
connection.send_bytes(url)
log.debug('SPIDER PUSH : {}'.format(url))
except Exception, e:
log.warning('Spider PUSH OUT ERROR: {}'.format(e))
continue
示例3: workerConnection
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [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
示例4: push_out
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [as 别名]
def push_out(self):
address = ('127.0.0.1', Frontier.PUSH_OUT_PORT)
connection = Client(address, authkey=self.authkey)
log.info('Frontier : connection established from {}'.format(address))
counter = 0
while True:
url = self.back_queue.push_out()
if url:
try:
connection.send_bytes(url)
if counter % 2000 == 0:
log.info('FRONTIER PUSH TOTAL: {}'.format(counter))
counter += 1
except Exception,e:
log.warning('Frontier PUSH OUT ERROR:{}'.format(e))
continue
示例5: terms_client
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [as 别名]
def terms_client(config):
'''
CLI for terms server
'''
while True:
terms = raw_input('>> ')
if terms in ('quit', 'q', 'exit'):
break
conn = Client((config('kb_host'),
int(config('kb_port'))))
conn.send_bytes(terms)
conn.send_bytes('FINISH-TERMS')
recv, resp = '', ''
while recv != 'END':
resp = recv
recv = conn.recv_bytes()
print(recv)
conn.close()
print('bye!')
示例6: import_ontologies
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [as 别名]
def import_ontologies(config, session):
'''
get directory
cycle over trm files
if the file name not in importregistry
break file content on dots
send pieces to server
put filename in importregistry
'''
for module in get_plugins(config):
fname = os.path.join(os.path.dirname(module.__file__), 'ontology', 'terms.trm')
totell = []
kb = Client((config('kb_host'), int(config('kb_port'))))
with open(fname, 'r') as f:
for line in f.readlines():
if line:
kb.send_bytes(line)
kb.send_bytes('FINISH-TERMS')
for fact in iter(kb.recv_bytes, 'END'):
print(fact)
kb.close()
示例7: do_execute
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [as 别名]
def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False):
conn = Client((self.host, self.port))
conn.send_bytes(bytes(code, 'UTF-8'))
conn.send_bytes(bytes('FINISH-TERMS', 'UTF-8'))
recv, resp = bytes(), str()
while recv != b'END':
if recv:
resp += ', ' + recv.decode('UTF-8')
recv = conn.recv_bytes()
conn.close()
if not silent:
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
return {'status': 'ok',
# The base class increments the execution count
'execution_count': self.execution_count,
'payload': [],
'user_expressions': {},
}
示例8: run
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [as 别名]
def run(self):
kb = Client((self.config('kb_host'),
int(self.config('kb_port'))))
fact = self.fact
localdata.data = self.data
localdata.user = self.user
if self.user == 'admin':
fact += '.'
else:
fact = '(want %s, do %s).' % (self.user, fact)
kb.send_bytes(fact)
kb.send_bytes('FINISH-TERMS')
for fact in iter(kb.recv_bytes, 'END'):
toweb = apply_fact(self.tserver, fact)
toweb = json.dumps(toweb).encode('utf8')
try:
with self.wslock:
self.wsock.send(toweb)
except WebSocketError:
break
kb.close()
示例9: Wdb
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [as 别名]
#.........这里部分代码省略.........
if isinstance(cmd, str):
cmd = compile(cmd, fn or "<wdb>", "exec")
self.start_trace()
self.breakpoints.add(Breakpoint(fn, temporary=True))
try:
execute(cmd, globals, locals)
finally:
self.stop_trace()
def reset(self):
"""Refresh linecache"""
import linecache
linecache.checkcache()
def connect(self):
"""Connect to wdb server"""
log.info('Connecting socket on %s:%d' % (SOCKET_SERVER, SOCKET_PORT))
tries = 0
while not self._socket and tries < 10:
try:
self._socket = Client((SOCKET_SERVER, SOCKET_PORT))
except socket.error:
tries += 1
log.warning(
'You must start wdb.server. '
'(Retrying on %s:%d) [Try #%d]' % (
SOCKET_SERVER, SOCKET_PORT, tries))
if not self._socket:
log.error('Could not connect to server')
sys.exit(2)
Wdb._sockets.append(self._socket)
self._socket.send_bytes(self.uuid.encode('utf-8'))
def trace_dispatch(self, frame, event, arg):
"""This function is called every line,
function call, function return and exception during trace"""
fun = getattr(self, 'handle_' + event)
if fun and (
(event == 'line' and self.breaks(frame)) or
(event == 'exception' and
(self.full or frame == self.state.frame or
(self.below and frame.f_back == self.state.frame))) or
self.state.stops(frame, event)):
fun(frame, arg)
if event == 'return' and frame == self.state.frame:
# Upping state
if self.state.up():
# No more frames
self.stop_trace()
return
# Threading / Multiprocessing support
co = self.state.frame.f_code
if ((
co.co_filename.endswith('threading.py') and
co.co_name.endswith('_bootstrap_inner')
) or (self.state.frame.f_code.co_filename.endswith(
os.path.join('multiprocessing', 'process.py')) and
self.state.frame.f_code.co_name == '_bootstrap')):
# Thread / Process is dead
self.stop_trace()
self.die()
return
if (event == 'call' and not self.stepping and not self.full and
not (self.below and frame.f_back == self.state.frame) and
示例10: RemoteGdb
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [as 别名]
class RemoteGdb(object):
def __init__(self, vim, host, port):
self.vim = vim
self.sock = Client((host, port))
self.request_id = 0
self.response = {}
def send_command(self, **kwargs):
self.request_id += 1
try:
self.sock.send_bytes(json.dumps(dict(dict({'dest': 'gdb'}, **kwargs), request_id=self.request_id)).encode('utf-8'))
except IOError:
print "Broken pipe encountered sending to the proxy. Terminating Exterminator."
self.quit()
return self.request_id
def handle_events(self):
if not self.sock.poll():
return
while True:
try:
c = json.loads(self.sock.recv_bytes().decode('utf-8'))
except (IOError, EOFError):
print "Lost connection to GDB"
self.quit()
return
if c['op'] == 'goto':
window = self.find_window('navigation')
if window is None:
self.claim_window('navigation')
c['filename'] = os.path.abspath(c['filename'])
self.vim.command('badd %(filename)s' % c)
self.vim.command("buffer %(filename)s" % c)
self.vim.command("%(line)s" % c)
self.vim.command("%(line)skP" % c)
self.vim.command("norm zz")
elif c['op'] == 'disp':
winnr = int(self.vim.eval("winnr()"))
window = self.find_window('display', 'bot 15new')
self.vim.command("setlocal buftype=nowrite bufhidden=wipe modifiable nobuflisted noswapfile nowrap nonumber")
contents = [ c['expr'], c['contents'] ]
self.vim.current.window.buffer[:] = contents
self.vim.command("setlocal nomodifiable")
self.vim.command("%swincmd w" % winnr)
elif c['op'] == 'response':
self.response[c['request_id']] = c
elif c['op'] == 'refresh':
GDBPlugin = self.vim.bindeval('g:NERDTreeGDBPlugin')
NERDTreeFromJSON = self.vim.Function('NERDTreeFromJSON')
NERDTreeFromJSON(c['expr'], GDBPlugin)
elif c['op'] == 'place':
c['filename'] = os.path.abspath(c['filename'])
self.vim.command("badd %s" % c['filename'].replace('$', '\\$'))
c['bufnr'] = self.vim.eval("bufnr('%(filename)s')" % c)
self.vim.command("sign place %(num)s name=%(name)s line=%(line)s buffer=%(bufnr)s" % c)
elif c['op'] == 'replace':
self.vim.command("sign place %(num)s name=%(name)s file=%(filename)s" % c)
elif c['op'] == 'unplace':
self.vim.command("sign unplace %(num)s" % c)
elif c['op'] == 'quit':
self.quit()
return
if not self.sock.poll():
return
def quit(self):
self.vim.command("sign unplace *")
winnr = int(self.vim.eval("winnr()"))
window = self.find_window('display')
if window is not None:
self.vim.command("q")
self.vim.command("%swincmd w" % winnr)
self.vim.gdb = None
try:
self.send_command(dest='proxy', op='quit')
except:
pass
def send_trap(self):
self.send_command(dest='proxy', op='trap')
def send_quit(self):
self.send_command(op='quit')
def send_continue(self):
self.send_command(op='go')
self.send_trap()
def send_exec(self, comm):
self.send_command(op='exec', comm=comm)
self.send_trap()
def disable_break(self, filename, line):
self.send_command(op='disable', loc=(filename, line))
self.send_trap()
def toggle_break(self, filename, line):
self.send_command(op='toggle', loc=(filename, line))
self.send_trap()
#.........这里部分代码省略.........
示例11: Environment
# 需要导入模块: from multiprocessing.connection import Client [as 别名]
# 或者: from multiprocessing.connection.Client import send_bytes [as 别名]
class Environment(object):
"""Supplement server client"""
def __init__(self, executable=None, env=None, logfile=None):
"""Environment constructor
:param executable: path to python executable. May be path to virtualenv interpreter
start script like ``/path/to/venv/bin/python``.
:param env: environment variables dict, e.g. ``DJANGO_SETTINGS_MODULE`` value.
:param logfile: explicit log file, can be passed via environment SUPP_LOG_FILE
"""
self.executable = executable or sys.executable
self.env = env
self.logfile = logfile
self.prepare_thread = None
self.prepare_lock = Lock()
def _run(self):
from subprocess import Popen
from multiprocessing.connection import Client, arbitrary_address
if sys.platform == 'win32':
addr = arbitrary_address('AF_PIPE')
else:
addr = arbitrary_address('AF_UNIX')
supp_server = os.path.join(os.path.dirname(__file__), 'server.py')
args = [self.executable, supp_server, addr]
env = os.environ.copy()
if self.env:
env.update(self.env)
if self.logfile and 'SUPP_LOG_FILE' not in env:
env['SUPP_LOG_FILE'] = self.logfile
self.proc = Popen(args, env=env)
start = time.time()
while True:
try:
self.conn = Client(addr)
except Exception as e:
if time.time() - start > 5:
raise Exception('Supp server launching timeout exceed: ' + str(e))
time.sleep(0.3)
else:
break
def _threaded_run(self):
try:
self._run()
finally:
self.prepare_thread = None
def prepare(self):
with self.prepare_lock:
if self.prepare_thread:
return
if hasattr(self, 'conn'):
return
self.prepare_thread = Thread(target=self._threaded_run)
self.prepare_thread.start()
def run(self):
with self.prepare_lock:
if self.prepare_thread:
self.prepare_thread.join()
if not hasattr(self, 'conn'):
self._run()
def _call(self, name, *args, **kwargs):
try:
self.conn
except AttributeError:
self.run()
self.conn.send_bytes(dumps((name, args, kwargs)))
result, is_ok = loads(self.conn.recv_bytes())
if is_ok:
return result
else:
raise Exception(result[1])
def lint(self, source, filename, syntax_only=False):
return self._call('lint', source, filename, syntax_only)
def assist(self, source, position, filename):
"""Return completion match and list of completion proposals
:param source: code source
:param position: tuple of (line, column)
#.........这里部分代码省略.........