@@ -531,12 +531,10 @@ def call_at(self, when, callback, *args):
531
531
532
532
Absolute time corresponds to the event loop's time() method.
533
533
"""
534
- if (coroutines .iscoroutine (callback )
535
- or coroutines .iscoroutinefunction (callback )):
536
- raise TypeError ("coroutines cannot be used with call_at()" )
537
534
self ._check_closed ()
538
535
if self ._debug :
539
536
self ._check_thread ()
537
+ self ._check_callback (callback , 'call_at' )
540
538
timer = events .TimerHandle (when , callback , args , self )
541
539
if timer ._source_traceback :
542
540
del timer ._source_traceback [- 1 ]
@@ -554,18 +552,24 @@ def call_soon(self, callback, *args):
554
552
Any positional arguments after the callback will be passed to
555
553
the callback when it is called.
556
554
"""
555
+ self ._check_closed ()
557
556
if self ._debug :
558
557
self ._check_thread ()
558
+ self ._check_callback (callback , 'call_soon' )
559
559
handle = self ._call_soon (callback , args )
560
560
if handle ._source_traceback :
561
561
del handle ._source_traceback [- 1 ]
562
562
return handle
563
563
564
+ def _check_callback (self , callback , method ):
565
+ if (coroutines .iscoroutine (callback ) or
566
+ coroutines .iscoroutinefunction (callback )):
567
+ raise TypeError (
568
+ "coroutines cannot be used with {}()" .format (method ))
569
+ if isinstance (callback , events .Handle ):
570
+ raise TypeError ('A Handle is not a callback' )
571
+
564
572
def _call_soon (self , callback , args ):
565
- if (coroutines .iscoroutine (callback )
566
- or coroutines .iscoroutinefunction (callback )):
567
- raise TypeError ("coroutines cannot be used with call_soon()" )
568
- self ._check_closed ()
569
573
handle = events .Handle (callback , args , self )
570
574
if handle ._source_traceback :
571
575
del handle ._source_traceback [- 1 ]
@@ -591,17 +595,19 @@ def _check_thread(self):
591
595
592
596
def call_soon_threadsafe (self , callback , * args ):
593
597
"""Like call_soon(), but thread-safe."""
598
+ self ._check_closed ()
599
+ if self ._debug :
600
+ self ._check_callback (callback , 'call_soon_threadsafe' )
594
601
handle = self ._call_soon (callback , args )
595
602
if handle ._source_traceback :
596
603
del handle ._source_traceback [- 1 ]
597
604
self ._write_to_self ()
598
605
return handle
599
606
600
607
def run_in_executor (self , executor , func , * args ):
601
- if (coroutines .iscoroutine (func )
602
- or coroutines .iscoroutinefunction (func )):
603
- raise TypeError ("coroutines cannot be used with run_in_executor()" )
604
608
self ._check_closed ()
609
+ if self ._debug :
610
+ self ._check_callback (func , 'run_in_executor' )
605
611
if isinstance (func , events .Handle ):
606
612
assert not args
607
613
assert not isinstance (func , events .TimerHandle )
0 commit comments