This repository was archived by the owner on Nov 23, 2017. It is now read-only.
File tree 3 files changed +11
-20
lines changed
3 files changed +11
-20
lines changed Original file line number Diff line number Diff line change @@ -294,9 +294,6 @@ def __init__(self):
294
294
# Set to True when `loop.shutdown_asyncgens` is called.
295
295
self ._asyncgens_shutdown_called = False
296
296
297
- # Future that isn't resolved while the loop is running.
298
- self ._forever_fut = None
299
-
300
297
def __repr__ (self ):
301
298
return ('<%s running=%s closed=%s debug=%s>'
302
299
% (self .__class__ .__name__ , self .is_running (),
@@ -433,12 +430,8 @@ def shutdown_asyncgens(self):
433
430
'asyncgen' : agen
434
431
})
435
432
436
- def get_forever_future (self ):
437
- return self ._forever_fut
438
-
439
433
def run_forever (self ):
440
434
"""Run until stop() is called."""
441
- self ._forever_fut = self .create_future ()
442
435
self ._check_closed ()
443
436
if self .is_running ():
444
437
raise RuntimeError ('This event loop is already running' )
@@ -457,14 +450,7 @@ def run_forever(self):
457
450
self ._run_once ()
458
451
if self ._stopping :
459
452
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 )
466
453
finally :
467
- self ._forever_fut = None
468
454
self ._stopping = False
469
455
self ._thread_id = None
470
456
events ._set_running_loop (None )
Original file line number Diff line number Diff line change @@ -512,9 +512,6 @@ def get_debug(self):
512
512
def set_debug (self , enabled ):
513
513
raise NotImplementedError
514
514
515
- def get_forever_future (self ):
516
- raise NotImplementedError
517
-
518
515
519
516
class AbstractEventLoopPolicy :
520
517
"""Abstract policy for accessing the event loop."""
Original file line number Diff line number Diff line change 9
9
from . import events
10
10
11
11
12
+ def _isasyncgen (obj ):
13
+ if hasattr (inspect , 'isasyncgen' ):
14
+ return inspect .isasyncgen (obj )
15
+ return False
16
+
17
+
12
18
@coroutines .coroutine
13
19
def forever ():
14
20
"""Wait until the current event loop stops running.
@@ -68,8 +74,10 @@ async def main():
68
74
if not isinstance (threading .current_thread (), threading ._MainThread ):
69
75
raise RuntimeError (
70
76
"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 ))
73
81
74
82
loop = events .new_event_loop ()
75
83
try :
@@ -78,7 +86,7 @@ async def main():
78
86
if debug :
79
87
loop .set_debug (True )
80
88
81
- if inspect . isasyncgen (coro ):
89
+ if _isasyncgen (coro ):
82
90
result = None
83
91
loop .run_until_complete (coro .asend (None ))
84
92
try :
You can’t perform that action at this time.
0 commit comments