File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -202,6 +202,33 @@ def get_event_loop(self) -> _AbstractEventLoop:
202202
203203 Returns an instance of EventLoop or raises an exception.
204204 """
205+ if (
206+ self ._local ._loop is None
207+ and threading .current_thread () is threading .main_thread ()
208+ ):
209+ # Replicate the behavior of asyncio.get_event_loop() as closely
210+ # as possible, including the warning and stack level.
211+ stacklevel = 2
212+ try :
213+ f = _sys ._getframe (1 )
214+ except AttributeError :
215+ pass
216+ else :
217+ # Move up the call stack so that the warning is attached
218+ # to the line outside uvloop itself.
219+ while f :
220+ module = f .f_globals ['__name__' ]
221+ if not (module == 'uvloop' or module .startswith ('uvloop.' )):
222+ break
223+ f = f .f_back
224+ stacklevel += 1
225+ _warnings .warn (
226+ 'There is no current event loop' ,
227+ DeprecationWarning ,
228+ stacklevel = stacklevel
229+ )
230+ self ._local ._loop = self ._loop_factory ()
231+
205232 if self ._local ._loop is None :
206233 raise RuntimeError (
207234 'There is no current event loop in thread %r.'
You can’t perform that action at this time.
0 commit comments