Skip to content

Commit 1311974

Browse files
committed
Fix idle() not working in Windows
- Remove event-based idling - Add back while-true-based idling
1 parent 093d1e0 commit 1311974

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

pyrogram/methods/utilities/idle.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818

1919
import asyncio
2020
import logging
21-
import signal
21+
from signal import signal, SIGINT, SIGTERM, SIGABRT
2222

2323
log = logging.getLogger(__name__)
2424

25-
loop = asyncio.get_event_loop()
26-
event = asyncio.Event()
25+
is_idling = False
2726

2827

2928
async def idle():
@@ -64,15 +63,18 @@ async def idle():
6463
app2.stop()
6564
app3.stop()
6665
"""
66+
global is_idling
6767

68-
def handler():
69-
log.info("Stop signal received")
70-
event.set()
68+
def signal_handler(_, __):
69+
global is_idling
7170

72-
asyncio.get_event_loop().add_signal_handler(signal.SIGINT, handler)
71+
logging.info("Stop signal received ({}). Exiting...".format(_))
72+
is_idling = False
7373

74-
log.info("Idle started")
75-
await event.wait()
74+
for s in (SIGINT, SIGTERM, SIGABRT):
75+
signal(s, signal_handler)
7676

77-
log.info("Idle stopped")
78-
event.clear()
77+
is_idling = True
78+
79+
while is_idling:
80+
await asyncio.sleep(1)

0 commit comments

Comments
 (0)