本文整理汇总了Python中tulip.get_event_loop函数的典型用法代码示例。如果您正苦于以下问题:Python get_event_loop函数的具体用法?Python get_event_loop怎么用?Python get_event_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_event_loop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run
def _run(self):
def factory():
return tulip.http.WSGIServerHttpProtocol(
self.wsgi, readpayload=True)
# insert sockets to event_loop
for sock in self.sockets:
self.ev_loop.start_serving(factory, sock=sock)
# If our parent changed then we shut down.
pid = os.getpid()
try:
while self.alive:
self.notify()
if pid == os.getpid() and self.ppid != os.getppid():
self.log.info("Parent changed, shutting down: %s", self)
break
yield from tulip.sleep(1.0)
except KeyboardInterrupt:
pass
tulip.get_event_loop().stop()
tulip.get_event_loop().close()
示例2: init_process
def init_process(self):
# create new event_loop after fork
tulip.get_event_loop().close()
self.ev_loop = tulip.new_event_loop()
tulip.set_event_loop(self.ev_loop)
super().init_process()
示例3: handle_noargs
def handle_noargs(self, **options):
clients = [run(row, col, SIZE)
for row in range(SIZE)
for col in range(SIZE)]
try:
tulip.get_event_loop().run_until_complete(tulip.wait(clients))
except KeyboardInterrupt:
pass
示例4: test_gameoflife
def test_gameoflife(self):
# Reduce size before opening the browser so it gets the right size.
tulip.get_event_loop().run_until_complete(client.reset(5))
# This is just for the eye candy.
self.selenium.get(self.live_server_url + reverse('gameoflife.views.watch'))
# Run the game, with and without a pattern.
call_command('gameoflife', size=5, speed=100, steps=5)
call_command('gameoflife', size=5, speed=100, steps=5,
pattern='gameoflife/patterns/blinker')
示例5: start
def start(self):
# start server
self.loop = loop = tulip.new_event_loop()
tulip.set_event_loop(loop)
def stop():
self.loop.stop()
os._exit(0)
loop.add_signal_handler(signal.SIGINT, stop)
# heartbeat
tulip.Task(self.heartbeat())
tulip.get_event_loop().run_forever()
os._exit(0)
示例6: bar
def bar(client):
client.log('Starting bar work in another thread.')
loop = tulip.get_event_loop()
widgets = yield from loop.run_in_executor(None, bar_synchronous)
for widget in widgets:
client.append_widget('bar', widget)
return 'bar is done!'
示例7: _negotiate
def _negotiate(self, call_after=None):
"""
Negotiate options before prompting for input, this method calls itself
every CONNECT_DEFERED up to the greater of the value CONNECT_MAXWAIT.
Negotiation completes when all ``pending_options`` of the
TelnetStreamReader have completed. Any options not negotiated
are displayed to the client as a warning, and ``display_prompt()``
is called for the first time, unless ``call_after`` specifies another
callback.
"""
if call_after is None:
call_after = self.first_prompt
assert callable(call_after), call_after
if self._closing:
return
loop = tulip.get_event_loop()
pending = [telopt._name_commands(opt)
for (opt, val) in self.stream.pending_option.items()
if val]
if self.duration < self.CONNECT_MINWAIT or (
pending and self.duration < self.CONNECT_MAXWAIT):
loop.call_later(self.CONNECT_DEFERED, self._negotiate, call_after)
return
elif pending:
self.log.warn('negotiate failed for {}.'.format(pending))
self.echo('\r\nnegotiate failed for {}.'.format(pending))
loop.call_soon(call_after)
示例8: scanport
def scanport(port):
ippat = "10.1.10.%d"
loop = tulip.get_event_loop()
loop.add_signal_handler(signal.SIGINT, loop.stop)
futs = []
for x in range(1, 255):
host = ippat % x
print("trying", host, port, end="\r", flush=True)
fut = tulip.Task(loop.create_connection(Scanner, host, port), timeout=1)
futs.append(fut)
loop.run_until_complete(tulip.sleep(0.001))
print()
for fut in futs:
try:
loop.run_until_complete(fut)
except tulip.CancelledError:
pass
except os.error as exc:
if exc.errno == 24:
print()
print(exc)
except Exception as exc:
print()
print(exc)
print()
loop.call_later(1, loop.stop)
loop.run_forever()
示例9: connect_read_pipe
def connect_read_pipe(file):
loop = tulip.get_event_loop()
stream_reader = streams.StreamReader(loop=loop)
def factory():
return streams.StreamReaderProtocol(stream_reader)
transport, _ = yield from loop.connect_read_pipe(factory, file)
return stream_reader, transport
示例10: main
def main():
loop = tulip.get_event_loop()
loop.add_signal_handler(signal.SIGINT, loop.stop)
f = loop.start_serving(HttpServer, '127.0.0.1', 8080)
x = loop.run_until_complete(f)
print('serving on', x.getsockname())
loop.run_forever()
示例11: retriable_download
def retriable_download(url, on_ok, on_error, retries=2, sleep=1, loop=None):
loop = loop or tulip.get_event_loop()
parsed = urlparse(url)
host = parsed.hostname
port = parsed.port or 80
path = parsed.path
def retry_on_error(exc):
print("ERROR {}. Retrying after {} s. Number or retries {}"
.format(exc, sleep, retries))
loop.call_later(
sleep,
retriable_download,
url, on_ok, on_error, retries-1, sleep, loop)
error_cb = on_error if retries == 0 else retry_on_error
# We wait for addrinfo to be resolved. When it is this func will be called.
def got_connection(transport, protocol):
# Set callbacks on data received
protocol.on_ok = on_ok
protocol.on_error = error_cb
# Send request to transport. Responce will be handled by callbacks.
request = (
b'GET ' + path.encode('ascii') + b' HTTP/1.1\n' +
b'HOST: ' + host.encode('ascii') + b'\n' +
b'\r\n')
transport.write(request)
# We do not want our callback's based code to be mixed in corutines code.
create_connection_with_cb(
got_connection, error_cb, loop, HTTPProtocol, host, port)
示例12: connection_made
def connection_made(self, transport):
print('connection made')
self.transport = transport
# start 5 seconds timeout timer
self.h_timeout = tulip.get_event_loop().call_later(
self.TIMEOUT, self.timeout)
示例13: __init__
def __init__(self):
self.loop = tulip.get_event_loop()
args = ARGS.parse_args()
if ':' in args.host:
args.host, port = args.host.split(':', 1)
args.port = int(port)
if args.iocp:
from tulip import windows_events
sys.argv.remove('--iocp')
logging.info('using iocp')
el = windows_events.ProactorEventLoop()
tulip.set_event_loop(el)
if args.ssl:
here = os.path.join(os.path.dirname(__file__), 'tests')
if args.certfile:
certfile = args.certfile or os.path.join(here, 'sample.crt')
keyfile = args.keyfile or os.path.join(here, 'sample.key')
else:
certfile = os.path.join(here, 'sample.crt')
keyfile = os.path.join(here, 'sample.key')
sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
sslcontext.load_cert_chain(certfile, keyfile)
else:
sslcontext = None
self.ssl = sslcontext
self.args = args
self.workers = []
示例14: main
def main():
url = len(sys.argv) > 1 and sys.argv[1] or 'http://example.com/'
loop = tulip.get_event_loop()
lock = tulip.locks.Lock()
loop.call_soon(download, 'http://example.com', lock)
loop.call_later(4, download, 'http://google.com', lock)
loop.call_later(8, download, 'http://some_lame_address_1111.com', lock)
loop.run_until_complete(tulip.sleep(20))
示例15: data_received
def data_received(self, data):
print('data received: ', data.decode())
self.transport.write(b'Re: ' + data)
# restart timeout timer
self.h_timeout.cancel()
self.h_timeout = tulip.get_event_loop().call_later(
self.TIMEOUT, self.timeout)