@@ -489,7 +489,7 @@ def time(self):
489489 """
490490 return time .monotonic ()
491491
492- def call_later (self , delay , callback , * args ):
492+ def call_later (self , delay , callback , * args , context = None ):
493493 """Arrange for a callback to be called at a given time.
494494
495495 Return a Handle: an opaque object with a cancel() method that
@@ -505,12 +505,13 @@ def call_later(self, delay, callback, *args):
505505 Any positional arguments after the callback will be passed to
506506 the callback when it is called.
507507 """
508- timer = self .call_at (self .time () + delay , callback , * args )
508+ timer = self .call_at (self .time () + delay , callback , * args ,
509+ context = context )
509510 if timer ._source_traceback :
510511 del timer ._source_traceback [- 1 ]
511512 return timer
512513
513- def call_at (self , when , callback , * args ):
514+ def call_at (self , when , callback , * args , context = None ):
514515 """Like call_later(), but uses an absolute time.
515516
516517 Absolute time corresponds to the event loop's time() method.
@@ -519,14 +520,14 @@ def call_at(self, when, callback, *args):
519520 if self ._debug :
520521 self ._check_thread ()
521522 self ._check_callback (callback , 'call_at' )
522- timer = events .TimerHandle (when , callback , args , self )
523+ timer = events .TimerHandle (when , callback , args , self , context )
523524 if timer ._source_traceback :
524525 del timer ._source_traceback [- 1 ]
525526 heapq .heappush (self ._scheduled , timer )
526527 timer ._scheduled = True
527528 return timer
528529
529- def call_soon (self , callback , * args ):
530+ def call_soon (self , callback , * args , context = None ):
530531 """Arrange for a callback to be called as soon as possible.
531532
532533 This operates as a FIFO queue: callbacks are called in the
@@ -540,7 +541,7 @@ def call_soon(self, callback, *args):
540541 if self ._debug :
541542 self ._check_thread ()
542543 self ._check_callback (callback , 'call_soon' )
543- handle = self ._call_soon (callback , args )
544+ handle = self ._call_soon (callback , args , context )
544545 if handle ._source_traceback :
545546 del handle ._source_traceback [- 1 ]
546547 return handle
@@ -555,8 +556,8 @@ def _check_callback(self, callback, method):
555556 f'a callable object was expected by { method } (), '
556557 f'got { callback !r} ' )
557558
558- def _call_soon (self , callback , args ):
559- handle = events .Handle (callback , args , self )
559+ def _call_soon (self , callback , args , context ):
560+ handle = events .Handle (callback , args , self , context )
560561 if handle ._source_traceback :
561562 del handle ._source_traceback [- 1 ]
562563 self ._ready .append (handle )
@@ -579,12 +580,12 @@ def _check_thread(self):
579580 "Non-thread-safe operation invoked on an event loop other "
580581 "than the current one" )
581582
582- def call_soon_threadsafe (self , callback , * args ):
583+ def call_soon_threadsafe (self , callback , * args , context = None ):
583584 """Like call_soon(), but thread-safe."""
584585 self ._check_closed ()
585586 if self ._debug :
586587 self ._check_callback (callback , 'call_soon_threadsafe' )
587- handle = self ._call_soon (callback , args )
588+ handle = self ._call_soon (callback , args , context )
588589 if handle ._source_traceback :
589590 del handle ._source_traceback [- 1 ]
590591 self ._write_to_self ()
0 commit comments