本文整理汇总了Python中tulip.get_event_loop函数的典型用法代码示例。如果您正苦于以下问题:Python get_event_loop函数的具体用法?Python get_event_loop怎么用?Python get_event_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_event_loop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:zakdances,项目名称:gtulip,代码行数:25,代码来源:worker.py
示例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()
开发者ID:zakdances,项目名称:gtulip,代码行数:8,代码来源:worker.py
示例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
开发者ID:yanchao727,项目名称:django-c10k-demo,代码行数:8,代码来源:gameoflife.py
示例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')
开发者ID:azizur77,项目名称:django-c10k-demo,代码行数:12,代码来源:test_integration.py
示例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)
开发者ID:oohlaf,项目名称:asynchttp,代码行数:15,代码来源:wssrv.py
示例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!'
开发者ID:feihong,项目名称:tulip-talk,代码行数:7,代码来源:demo.py
示例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)
开发者ID:tehmaze,项目名称:telnetlib3,代码行数:28,代码来源:server.py
示例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()
开发者ID:photonxp,项目名称:pycon2014,代码行数:27,代码来源:scanner.py
示例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
开发者ID:concordusapps,项目名称:tulip,代码行数:7,代码来源:child_process.py
示例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()
开发者ID:waytai,项目名称:httpclient,代码行数:7,代码来源:wsserver.py
示例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)
开发者ID:Drizzt1991,项目名称:asyncLessons,代码行数:31,代码来源:lesson3download.py
示例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)
开发者ID:concordusapps,项目名称:tulip,代码行数:7,代码来源:tcp_echo.py
示例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 = []
开发者ID:avelino,项目名称:nacho,代码行数:32,代码来源:multithreading.py
示例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))
开发者ID:Drizzt1991,项目名称:asyncLessons,代码行数:8,代码来源:lesson3download.py
示例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)
开发者ID:concordusapps,项目名称:tulip,代码行数:8,代码来源:tcp_echo.py
示例16: download
def download(url, lock):
loop = tulip.get_event_loop()
print('DOWNLOADING', url)
retriable_download(
url,
on_ok=lambda x: print("RECEIVED OK", len(x)),
on_error=lambda exc: print("RECEIVED ERROR", exc),
loop=loop
)
开发者ID:Drizzt1991,项目名称:asyncLessons,代码行数:9,代码来源:lesson3download.py
示例17: connect
def connect(dsn=None, *, loop=None):
if loop is None:
loop = tulip.get_event_loop()
conn = psycopg2.connect(
dsn=dsn,
cursor_factory=functools.partial(Cursor, loop=loop), async=1)
yield from wait(conn, loop)
return conn
开发者ID:gjcarneiro,项目名称:psycotulip,代码行数:9,代码来源:__init__.py
示例18: test_drive_client
def test_drive_client():
loop = tulip.get_event_loop()
print("in test driver")
client = AsyncClient(loop=loop)
yield from client.connect()
resp = yield from client.set(b'foozle', b'yay')
print(resp)
val = yield from client.get(b'foozle')
print(val)
return val
开发者ID:patricklaw,项目名称:mc,代码行数:10,代码来源:client.py
示例19: first_prompt
def first_prompt(self, call_after=None):
""" XXX First time prompt fire
"""
call_after = self.display_prompt if call_after is None else call_after
assert callable(call_after), call_after
self.log.info(self.about_connection())
# conceivably, you could use various callback mechanisms to
# relate to authenticating or other multi-state login process.
loop = tulip.get_event_loop()
loop.call_soon(call_after)
开发者ID:tehmaze,项目名称:telnetlib3,代码行数:11,代码来源:server.py
示例20: __init__
def __init__(self, *, log=logging, debug=False,
keep_alive=None, loop=None, **kwargs):
self.__dict__.update(kwargs)
self.log = log
self.debug = debug
self._keep_alive_period = keep_alive # number of seconds to keep alive
if keep_alive and loop is None:
loop = tulip.get_event_loop()
self._loop = loop
开发者ID:oohlaf,项目名称:asynchttp,代码行数:11,代码来源:server.py
注:本文中的tulip.get_event_loop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论