bpo-32436: Implement PEP 567 (#5027) · python/cpython@f23746a (original) (raw)

`@@ -489,7 +489,7 @@ def time(self):

`

489

489

` """

`

490

490

`return time.monotonic()

`

491

491

``

492

``

`-

def call_later(self, delay, callback, *args):

`

``

492

`+

def call_later(self, delay, callback, *args, context=None):

`

493

493

`"""Arrange for a callback to be called at a given time.

`

494

494

``

495

495

` Return a Handle: an opaque object with a cancel() method that

`

`@@ -505,12 +505,13 @@ def call_later(self, delay, callback, *args):

`

505

505

` Any positional arguments after the callback will be passed to

`

506

506

` the callback when it is called.

`

507

507

` """

`

508

``

`-

timer = self.call_at(self.time() + delay, callback, *args)

`

``

508

`+

timer = self.call_at(self.time() + delay, callback, *args,

`

``

509

`+

context=context)

`

509

510

`if timer._source_traceback:

`

510

511

`del timer._source_traceback[-1]

`

511

512

`return timer

`

512

513

``

513

``

`-

def call_at(self, when, callback, *args):

`

``

514

`+

def call_at(self, when, callback, *args, context=None):

`

514

515

`"""Like call_later(), but uses an absolute time.

`

515

516

``

516

517

` Absolute time corresponds to the event loop's time() method.

`

`@@ -519,14 +520,14 @@ def call_at(self, when, callback, *args):

`

519

520

`if self._debug:

`

520

521

`self._check_thread()

`

521

522

`self._check_callback(callback, 'call_at')

`

522

``

`-

timer = events.TimerHandle(when, callback, args, self)

`

``

523

`+

timer = events.TimerHandle(when, callback, args, self, context)

`

523

524

`if timer._source_traceback:

`

524

525

`del timer._source_traceback[-1]

`

525

526

`heapq.heappush(self._scheduled, timer)

`

526

527

`timer._scheduled = True

`

527

528

`return timer

`

528

529

``

529

``

`-

def call_soon(self, callback, *args):

`

``

530

`+

def call_soon(self, callback, *args, context=None):

`

530

531

`"""Arrange for a callback to be called as soon as possible.

`

531

532

``

532

533

` This operates as a FIFO queue: callbacks are called in the

`

`@@ -540,7 +541,7 @@ def call_soon(self, callback, *args):

`

540

541

`if self._debug:

`

541

542

`self._check_thread()

`

542

543

`self._check_callback(callback, 'call_soon')

`

543

``

`-

handle = self._call_soon(callback, args)

`

``

544

`+

handle = self._call_soon(callback, args, context)

`

544

545

`if handle._source_traceback:

`

545

546

`del handle._source_traceback[-1]

`

546

547

`return handle

`

`@@ -555,8 +556,8 @@ def _check_callback(self, callback, method):

`

555

556

`f'a callable object was expected by {method}(), '

`

556

557

`f'got {callback!r}')

`

557

558

``

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)

`

560

561

`if handle._source_traceback:

`

561

562

`del handle._source_traceback[-1]

`

562

563

`self._ready.append(handle)

`

`@@ -579,12 +580,12 @@ def _check_thread(self):

`

579

580

`"Non-thread-safe operation invoked on an event loop other "

`

580

581

`"than the current one")

`

581

582

``

582

``

`-

def call_soon_threadsafe(self, callback, *args):

`

``

583

`+

def call_soon_threadsafe(self, callback, *args, context=None):

`

583

584

`"""Like call_soon(), but thread-safe."""

`

584

585

`self._check_closed()

`

585

586

`if self._debug:

`

586

587

`self._check_callback(callback, 'call_soon_threadsafe')

`

587

``

`-

handle = self._call_soon(callback, args)

`

``

588

`+

handle = self._call_soon(callback, args, context)

`

588

589

`if handle._source_traceback:

`

589

590

`del handle._source_traceback[-1]

`

590

591

`self._write_to_self()

`