This repository was archived by the owner on Nov 23, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +11
-20
lines changed
Expand file tree Collapse file tree 3 files changed +11
-20
lines changed Original file line number Diff line number Diff line change @@ -294,9 +294,6 @@ def __init__(self):
294294 # Set to True when `loop.shutdown_asyncgens` is called.
295295 self ._asyncgens_shutdown_called = False
296296
297- # Future that isn't resolved while the loop is running.
298- self ._forever_fut = None
299-
300297 def __repr__ (self ):
301298 return ('<%s running=%s closed=%s debug=%s>'
302299 % (self .__class__ .__name__ , self .is_running (),
@@ -433,12 +430,8 @@ def shutdown_asyncgens(self):
433430 'asyncgen' : agen
434431 })
435432
436- def get_forever_future (self ):
437- return self ._forever_fut
438-
439433 def run_forever (self ):
440434 """Run until stop() is called."""
441- self ._forever_fut = self .create_future ()
442435 self ._check_closed ()
443436 if self .is_running ():
444437 raise RuntimeError ('This event loop is already running' )
@@ -457,14 +450,7 @@ def run_forever(self):
457450 self ._run_once ()
458451 if self ._stopping :
459452 break
460- except BaseException as ex :
461- self ._forever_fut .set_exception (ex )
462- self ._forever_fut ._log_traceback = False
463- raise ex
464- else :
465- self ._forever_fut .set_result (None )
466453 finally :
467- self ._forever_fut = None
468454 self ._stopping = False
469455 self ._thread_id = None
470456 events ._set_running_loop (None )
Original file line number Diff line number Diff line change @@ -512,9 +512,6 @@ def get_debug(self):
512512 def set_debug (self , enabled ):
513513 raise NotImplementedError
514514
515- def get_forever_future (self ):
516- raise NotImplementedError
517-
518515
519516class AbstractEventLoopPolicy :
520517 """Abstract policy for accessing the event loop."""
Original file line number Diff line number Diff line change 99from . import events
1010
1111
12+ def _isasyncgen (obj ):
13+ if hasattr (inspect , 'isasyncgen' ):
14+ return inspect .isasyncgen (obj )
15+ return False
16+
17+
1218@coroutines .coroutine
1319def forever ():
1420 """Wait until the current event loop stops running.
@@ -68,8 +74,10 @@ async def main():
6874 if not isinstance (threading .current_thread (), threading ._MainThread ):
6975 raise RuntimeError (
7076 "asyncio.run() must be called from the main thread" )
71- # if not coroutines.iscoroutine(coro):
72- # raise ValueError("a coroutine was expected, got {!r}".format(coro))
77+ if not coroutines .iscoroutine (coro ) and not _isasyncgen (coro ):
78+ raise ValueError (
79+ "a coroutine or an asynchronous generator was expected, "
80+ "got {!r}" .format (coro ))
7381
7482 loop = events .new_event_loop ()
7583 try :
@@ -78,7 +86,7 @@ async def main():
7886 if debug :
7987 loop .set_debug (True )
8088
81- if inspect . isasyncgen (coro ):
89+ if _isasyncgen (coro ):
8290 result = None
8391 loop .run_until_complete (coro .asend (None ))
8492 try :
You can’t perform that action at this time.
0 commit comments