@@ -531,12 +531,10 @@ def call_at(self, when, callback, *args):
531531
532532 Absolute time corresponds to the event loop's time() method.
533533 """
534- if (coroutines .iscoroutine (callback )
535- or coroutines .iscoroutinefunction (callback )):
536- raise TypeError ("coroutines cannot be used with call_at()" )
537534 self ._check_closed ()
538535 if self ._debug :
539536 self ._check_thread ()
537+ self ._check_callback (callback , 'call_at' )
540538 timer = events .TimerHandle (when , callback , args , self )
541539 if timer ._source_traceback :
542540 del timer ._source_traceback [- 1 ]
@@ -554,18 +552,24 @@ def call_soon(self, callback, *args):
554552 Any positional arguments after the callback will be passed to
555553 the callback when it is called.
556554 """
555+ self ._check_closed ()
557556 if self ._debug :
558557 self ._check_thread ()
558+ self ._check_callback (callback , 'call_soon' )
559559 handle = self ._call_soon (callback , args )
560560 if handle ._source_traceback :
561561 del handle ._source_traceback [- 1 ]
562562 return handle
563563
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+
564572 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 ()
569573 handle = events .Handle (callback , args , self )
570574 if handle ._source_traceback :
571575 del handle ._source_traceback [- 1 ]
@@ -591,17 +595,19 @@ def _check_thread(self):
591595
592596 def call_soon_threadsafe (self , callback , * args ):
593597 """Like call_soon(), but thread-safe."""
598+ self ._check_closed ()
599+ if self ._debug :
600+ self ._check_callback (callback , 'call_soon_threadsafe' )
594601 handle = self ._call_soon (callback , args )
595602 if handle ._source_traceback :
596603 del handle ._source_traceback [- 1 ]
597604 self ._write_to_self ()
598605 return handle
599606
600607 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()" )
604608 self ._check_closed ()
609+ if self ._debug :
610+ self ._check_callback (func , 'run_in_executor' )
605611 if isinstance (func , events .Handle ):
606612 assert not args
607613 assert not isinstance (func , events .TimerHandle )
0 commit comments