Fix idle() not working in Windows
- Remove event-based idling - Add back while-true-based idling
This commit is contained in:
parent
093d1e0dcb
commit
1311974fde
@ -18,12 +18,11 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import signal
|
from signal import signal, SIGINT, SIGTERM, SIGABRT
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
is_idling = False
|
||||||
event = asyncio.Event()
|
|
||||||
|
|
||||||
|
|
||||||
async def idle():
|
async def idle():
|
||||||
@ -64,15 +63,18 @@ async def idle():
|
|||||||
app2.stop()
|
app2.stop()
|
||||||
app3.stop()
|
app3.stop()
|
||||||
"""
|
"""
|
||||||
|
global is_idling
|
||||||
|
|
||||||
def handler():
|
def signal_handler(_, __):
|
||||||
log.info("Stop signal received")
|
global is_idling
|
||||||
event.set()
|
|
||||||
|
|
||||||
asyncio.get_event_loop().add_signal_handler(signal.SIGINT, handler)
|
logging.info("Stop signal received ({}). Exiting...".format(_))
|
||||||
|
is_idling = False
|
||||||
|
|
||||||
log.info("Idle started")
|
for s in (SIGINT, SIGTERM, SIGABRT):
|
||||||
await event.wait()
|
signal(s, signal_handler)
|
||||||
|
|
||||||
log.info("Idle stopped")
|
is_idling = True
|
||||||
event.clear()
|
|
||||||
|
while is_idling:
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user