Skip to content

Commit 6e9124f

Browse files
committed
process: Kill _set_result_unless_cancelled
1 parent 6440c3f commit 6e9124f

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

uvloop/handles/process.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ cdef class UVProcessTransport(UVProcess):
4848
cdef _pipe_connection_lost(self, int fd, exc)
4949
cdef _pipe_data_received(self, int fd, data)
5050

51+
cdef _call_connection_made(self, waiter)
52+
5153
@staticmethod
5254
cdef UVProcessTransport new(Loop loop, protocol, args, env, cwd,
5355
start_new_session,

uvloop/handles/process.pyx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,18 @@ cdef class UVProcessTransport(UVProcess):
323323
iocnt.flags = uv.UV_INHERIT_FD
324324
iocnt.data.fd = io[idx]
325325

326+
cdef _call_connection_made(self, waiter):
327+
try:
328+
self._protocol.connection_made(self)
329+
except Exception as ex:
330+
if waiter is not None and not waiter.cancelled():
331+
waiter.set_exception(ex)
332+
else:
333+
raise
334+
else:
335+
if waiter is not None and not waiter.cancelled():
336+
waiter.set_result(True)
337+
326338
@staticmethod
327339
cdef UVProcessTransport new(Loop loop, protocol, args, env,
328340
cwd, start_new_session,
@@ -347,9 +359,11 @@ cdef class UVProcessTransport(UVProcess):
347359

348360
# By the time `protocol.connection_made` is called,
349361
# all three pipes should be done with initializing.
350-
loop.call_soon(protocol.connection_made, handle)
351-
if waiter is not None:
352-
loop.call_soon(_set_result_unless_cancelled, waiter, True)
362+
loop._call_soon_handle(
363+
new_MethodHandle1(loop,
364+
"UVProcessTransport._call_connection_made",
365+
<method1_t*>&handle._call_connection_made,
366+
handle, waiter))
353367

354368
return handle
355369

uvloop/loop.pyx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,13 +1621,6 @@ cdef inline void __loop_free_buffer(Loop loop):
16211621
loop._recv_buffer_in_use = 0
16221622

16231623

1624-
def _set_result_unless_cancelled(fut, result):
1625-
"""Helper setting the result only if the future was not cancelled."""
1626-
if fut.cancelled():
1627-
return
1628-
fut.set_result(result)
1629-
1630-
16311624
include "cbhandles.pyx"
16321625

16331626
include "handles/handle.pyx"

0 commit comments

Comments
 (0)