mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-23057: add loop self socket as wakeup fd for signals (#11135)
This commit is contained in:
parent
e3666fc8ef
commit
b5c8cfa1da
6 changed files with 104 additions and 6 deletions
|
|
@ -10,6 +10,7 @@ import io
|
|||
import os
|
||||
import socket
|
||||
import warnings
|
||||
import signal
|
||||
|
||||
from . import base_events
|
||||
from . import constants
|
||||
|
|
@ -489,6 +490,8 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
|
|||
self._accept_futures = {} # socket file descriptor => Future
|
||||
proactor.set_loop(self)
|
||||
self._make_self_pipe()
|
||||
self_no = self._csock.fileno()
|
||||
signal.set_wakeup_fd(self_no)
|
||||
|
||||
def _make_socket_transport(self, sock, protocol, waiter=None,
|
||||
extra=None, server=None):
|
||||
|
|
@ -529,6 +532,7 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
|
|||
if self.is_closed():
|
||||
return
|
||||
|
||||
signal.set_wakeup_fd(-1)
|
||||
# Call these methods before closing the event loop (before calling
|
||||
# BaseEventLoop.close), because they can schedule callbacks with
|
||||
# call_soon(), which is forbidden when the event loop is closed.
|
||||
|
|
@ -613,7 +617,6 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
|
|||
self._ssock.setblocking(False)
|
||||
self._csock.setblocking(False)
|
||||
self._internal_fds += 1
|
||||
self.call_soon(self._loop_self_reading)
|
||||
|
||||
def _loop_self_reading(self, f=None):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -308,6 +308,16 @@ class ProactorEventLoop(proactor_events.BaseProactorEventLoop):
|
|||
proactor = IocpProactor()
|
||||
super().__init__(proactor)
|
||||
|
||||
def run_forever(self):
|
||||
try:
|
||||
assert self._self_reading_future is None
|
||||
self.call_soon(self._loop_self_reading)
|
||||
super().run_forever()
|
||||
finally:
|
||||
if self._self_reading_future is not None:
|
||||
self._self_reading_future.cancel()
|
||||
self._self_reading_future = None
|
||||
|
||||
async def create_pipe_connection(self, protocol_factory, address):
|
||||
f = self._proactor.connect_pipe(address)
|
||||
pipe = await f
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue