kopia lustrzana https://github.com/cirospaciari/socketify.py
less hacks in event loop
rodzic
09552ac20c
commit
2cb40d67dc
|
@ -53,22 +53,8 @@ class Loop:
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.started = True
|
self.started = True
|
||||||
try:
|
self.loop.call_soon(self.keep_alive)
|
||||||
asyncio.events._set_running_loop(self.loop)
|
self.loop.run_forever()
|
||||||
self.loop._thread_id = threading.get_ident()
|
|
||||||
while self.started:
|
|
||||||
# run one step of asyncio
|
|
||||||
self.loop._stopping = True
|
|
||||||
self.loop._run_once()
|
|
||||||
# run one step of libuv
|
|
||||||
self.uv_loop.run_once()
|
|
||||||
finally:
|
|
||||||
self.loop._thread_id = None
|
|
||||||
asyncio.events._set_running_loop(None)
|
|
||||||
# Find all running tasks in main thread
|
|
||||||
pending = asyncio.all_tasks(self.loop)
|
|
||||||
# Run loop until tasks done
|
|
||||||
self.loop.run_until_complete(asyncio.gather(*pending))
|
|
||||||
# clean up uvloop
|
# clean up uvloop
|
||||||
self.uv_loop.stop()
|
self.uv_loop.stop()
|
||||||
|
|
||||||
|
@ -83,6 +69,7 @@ class Loop:
|
||||||
def stop(self):
|
def stop(self):
|
||||||
# Just mark as started = False and wait
|
# Just mark as started = False and wait
|
||||||
self.started = False
|
self.started = False
|
||||||
|
self.loop.stop()
|
||||||
|
|
||||||
# Exposes native loop for uWS
|
# Exposes native loop for uWS
|
||||||
def get_native_loop(self):
|
def get_native_loop(self):
|
||||||
|
@ -97,7 +84,6 @@ class Loop:
|
||||||
lambda f: future_handler(f, self.loop, self.exception_handler, response)
|
lambda f: future_handler(f, self.loop, self.exception_handler, response)
|
||||||
)
|
)
|
||||||
# force asyncio run once to enable req in async functions before first await
|
# force asyncio run once to enable req in async functions before first await
|
||||||
self.loop._stopping = True
|
|
||||||
self.loop._run_once()
|
self.loop._run_once()
|
||||||
|
|
||||||
return future
|
return future
|
||||||
|
|
Ładowanie…
Reference in New Issue