Skip to content

Commit

Permalink
IOLoop.current(): only create automatic loop on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Feb 9, 2023
1 parent c8f27ee commit 2a5de1f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tornado/ioloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import numbers
import os
import sys
import threading
import time
import math
import random
Expand Down Expand Up @@ -257,7 +258,9 @@ def current(instance: bool = True) -> Optional["IOLoop"]: # noqa: F811
except RuntimeError:
if not instance:
return None
# Create a new asyncio event loop for this thread.
if threading.current_thread() is not threading.main_thread():
raise
# Create a new asyncio event loop for the main thread.
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

Expand Down

0 comments on commit 2a5de1f

Please sign in to comment.