On 15.3.2014. 3:25, Guido van Rossum wrote:
I didn't say anything about connecting the client?
I misunderstood.
Anyway, isn't this the same situation, just a little later in the pipe's
life?
I think that the clean solution would be to make the PipeServer
aware of its async accept operation, so that it can be cancelled in
PipeServer.close() before the pipe is closed.
Do you have a specific change in mind?
Sure. The attached patch seems to fix the issue.
--- C:\Python-3.4.0rc3\Lib\asyncio\windows_events.py 2014-03-10 07:56:33.000000000 +0100
--- C:\Python-3.4.0rc3\Lib\asyncio\windows_events.py 2014-03-15 09:48:26.000000000 +0100
@@ -69,12 +69,13 @@
This is much like a bound, listening socket.
"""
def __init__(self, address):
self._address = address
self._free_instances = weakref.WeakSet()
self._pipe = self._server_pipe_handle(True)
+ self._accept_op = None
def _get_unconnected_pipe(self):
# Create new instance and return previous one. This ensures
# that (until the server is closed) there is always at least
# one pipe handle for address. Therefore if a client attempt
# to connect it will not fail with FileNotFoundError.
@@ -96,13 +97,18 @@
windows_utils.BUFSIZE, windows_utils.BUFSIZE,
_winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL)
pipe = windows_utils.PipeHandle(h)
self._free_instances.add(pipe)
return pipe
+ def _accept_started(self, accept_op):
+ self._accept_op = accept_op
+
def close(self):
+ if self._accept_op:
+ self._accept_op.cancel()
# Close all instances which have not been connected to by a client.
if self._address is not None:
for pipe in self._free_instances:
pipe.close()
self._pipe = None
self._address = None
@@ -152,12 +158,13 @@
self._make_duplex_pipe_transport(
pipe, protocol, extra={'addr': address})
pipe = server._get_unconnected_pipe()
if pipe is None:
return
f = self._proactor.accept_pipe(pipe)
+ server._accept_started(f)
except OSError as exc:
if pipe and pipe.fileno() != -1:
self.call_exception_handler({
'message': 'Pipe accept failed',
'exception': exc,
'pipe': pipe,