Skip to content

Commit 51f4950

Browse files
committed
Explicitly setting the event loop does not work on later Pythons
1 parent 218e864 commit 51f4950

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

redis/auth/token_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,22 @@ def start(
140140
) -> Callable[[], None]:
141141
self._listener = listener
142142

143+
# Event to block for initial execution.
143144
try:
144145
loop = asyncio.get_running_loop()
145146
except RuntimeError:
146147
# Run loop in a separate thread to unblock main thread.
147148
loop = asyncio.new_event_loop()
149+
asyncio.set_event_loop(loop)
150+
init_event = asyncio.Event()
151+
asyncio.set_event_loop(None)
148152
thread = threading.Thread(
149153
target=_start_event_loop_in_thread, args=(loop,), daemon=True
150154
)
151155
thread.start()
156+
else:
157+
init_event = asyncio.Event()
152158

153-
# Event to block for initial execution.
154-
init_event = asyncio.Event(loop=loop)
155159
self._init_timer = loop.call_later(
156160
0, self._renew_token, skip_initial, init_event
157161
)

0 commit comments

Comments
 (0)