本文整理汇总了Python中monocle.launch函数的典型用法代码示例。如果您正苦于以下问题:Python launch函数的具体用法?Python launch怎么用?Python launch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了launch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: launch_proc_with_pipes
def launch_proc_with_pipes(target, *args, **kwargs):
log_child, log_parent = Pipe()
child, parent = Pipe()
args = [target, log_child, child] + list(args)
p = Process(target=_wrapper_with_pipes, args=args, kwargs=kwargs)
p.start()
launch(log_receive, PipeChannel(log_parent))
return p, parent
示例2: run
def run(self):
""" Calls the start event on the transport and initiates pumping between upstream and downstream connections in both directions. """
self.transport.start()
self.drain()
monocle.launch(self.pumpUpstream)
yield self.pumpDownstream()
示例3: handle_dust
def handle_dust(conn):
print('handle_dust')
coder=yield handshake(conn)
client = Client()
yield client.connect('localhost', 9050)
monocle.launch(pump, conn, client, coder.decrypt)
yield pump(client, conn, coder.encrypt)
示例4: main
def main():
ch = Channel() # Create a new channel.
monocle.launch(generate, ch) # Start generate() as an o-routine.
while True:
prime = yield ch.recv()
print prime
ch1 = Channel()
filter(ch, ch1, prime)
ch = ch1
示例5: handle_socksDust
def handle_socksDust(conn):
print('connection')
client = Client()
yield client.connect('blanu.net', 7051)
coder=yield handshake(client)
monocle.launch(pump, conn, client, coder.encrypt)
yield pump(client, conn, coder.decrypt)
示例6: handle_dust
def handle_dust(conn):
print('handle_dust')
coder=yield handshake(conn)
buffer=FakeSocket()
monocle.launch(pump, conn, buffer, coder.decrypt)
monocle.launch(handle_socks, buffer.invert())
yield pump(buffer, conn, coder.encrypt, True)
print('done handling dust')
示例7: main
def main():
"""
The prime sieve: Daisy-chain filter processes together.
"""
ch = Channel() # Create a new channel.
monocle.launch(generate, ch) # Start generate() as an o-routine.
while True:
prime = yield ch.recv()
print(prime)
ch1 = Channel()
filter(ch, ch1, prime)
ch = ch1
示例8: launch_proc_with_sockets
def launch_proc_with_sockets(target, port, *args, **kwargs):
args = [target, port] + list(args)
p = Process(target=_wrapper_with_sockets, args=args, kwargs=kwargs)
p.start()
cb = Callback()
get_chan_service = partial(get_conn, cb)
service = Service(get_chan_service, port, bindaddr="127.0.0.1", backlog=1)
service._add()
conn = yield cb
yield service.stop()
chan = SocketChannel(conn)
main_chan, log_chan = make_subchannels(chan, ['main', 'log'])
launch(log_receive, log_chan)
yield Return(p, main_chan)
示例9: run
def run(self):
while self._running:
timeout = 0
if self._queue:
next = self._queue[-1][0] - time.time()
if next <= 0:
task = self._queue.pop()
launch(task[1], *task[2], **task[3])
else:
timeout = next
if self._map:
asyncore.loop(timeout=timeout, use_poll=True, count=1,
map=self._map)
else:
time.sleep(0.1)
示例10: handle_socks
def handle_socks(conn):
print('connection')
yield readHandshake(conn)
yield sendHandshake(conn)
dest=yield readRequest(conn)
yield sendResponse(dest, conn)
addr, port=uncompact(dest)
print(addr)
print(port)
client = Client()
yield client.connect(addr, port)
monocle.launch(pump, conn, client)
yield pump(client, conn)
示例11: _handler
def _handler(request):
try:
value = yield launch(self.handler, request)
code, headers, content = extract_response(value)
except Exception:
log_exception()
code, headers, content = 500, {}, "500 Internal Server Error"
try:
if request._disconnected:
return
request.setResponseCode(code)
headers.setdefault('Server', 'monocle/%s' % VERSION)
grouped_headers = {}
for name, value in headers.iteritems():
if name in grouped_headers:
grouped_headers[name].append(value)
else:
grouped_headers[name] = [value]
for name, value in grouped_headers.iteritems():
request.responseHeaders.setRawHeaders(name, value)
request.write(content)
# close connections with a 'close' header
if headers.get('Connection', '').lower() == 'close':
request.channel.persistent = False
request.finish()
except Exception:
log_exception()
raise
示例12: _handler
def _handler(tornado_request):
try:
headers = HttpHeaders()
for k, v in tornado_request.headers.get_all():
headers.add(k, v)
body_file = io.BytesIO(tornado_request.body)
request = HttpRequest(proto=tornado_request.version,
host=tornado_request.host,
method=tornado_request.method,
uri=tornado_request.uri,
args=tornado_request.arguments,
remote_ip=tornado_request.remote_ip,
headers=headers,
body=tornado_request.body,
body_file=body_file)
request._tornado_request = tornado_request
value = yield launch(self.handle_request, request)
code, headers, content = extract_response(value)
except:
code, headers, content = 500, {}, "500 Internal Server Error"
tornado_request.write("HTTP/1.1 %s %s\r\n" %
(code, responses.get(code, 'Unknown')))
headers.setdefault('Server', 'monocle/%s' % VERSION)
headers.setdefault('Content-Length', str(len(content)))
for name, value in headers.iteritems():
tornado_request.write("%s: %s\r\n" % (name, value))
tornado_request.write("\r\n")
tornado_request.write(content)
tornado_request.finish()
示例13: _handler
def _handler(request):
try:
code, headers, content = yield launch(self.handler, request)
except Exception, e:
print type(e), str(e)
log.log_exception()
code, headers, content = 500, {}, "500 Internal Server Error"
示例14: first_evlp
def first_evlp():
try:
yield sleep(1)
yield req()
yield launch(second)
finally:
eventloop.halt()
示例15: run
def run(fn):
ctx = {'exit_code': 0}
@_o
def _run_async(ctx):
try:
yield fn()
except Exception:
traceback.print_exc(file=sys.stdout)
ctx['exit_code'] = 1
finally:
eventloop.halt()
launch(_run_async, ctx)
eventloop.run()
sys.exit(ctx['exit_code'])