提交
This commit is contained in:
1 parent
59fafb92d5
commit
6abfb6e251
1512 files changed
+1565614
-275592
No files matched your search
@@ -92,31 +92,27 @@ cdef inline socket_dec_io_ref(sock):
|
||||
|
||||
|
||||
cdef inline run_in_context(context, method):
|
||||
# This method is internally used to workaround a reference issue that in
|
||||
# certain circumstances, inlined context.run() will not hold a reference to
|
||||
# the given method instance, which - if deallocated - will cause segfault.
|
||||
# See also: edgedb/edgedb#2222
|
||||
Py_INCREF(method)
|
||||
Context_Enter(context)
|
||||
try:
|
||||
return context.run(method)
|
||||
return method()
|
||||
finally:
|
||||
Py_DECREF(method)
|
||||
Context_Exit(context)
|
||||
|
||||
|
||||
cdef inline run_in_context1(context, method, arg):
|
||||
Py_INCREF(method)
|
||||
Context_Enter(context)
|
||||
try:
|
||||
return context.run(method, arg)
|
||||
return method(arg)
|
||||
finally:
|
||||
Py_DECREF(method)
|
||||
Context_Exit(context)
|
||||
|
||||
|
||||
cdef inline run_in_context2(context, method, arg1, arg2):
|
||||
Py_INCREF(method)
|
||||
Context_Enter(context)
|
||||
try:
|
||||
return context.run(method, arg1, arg2)
|
||||
return method(arg1, arg2)
|
||||
finally:
|
||||
Py_DECREF(method)
|
||||
Context_Exit(context)
|
||||
|
||||
|
||||
# Used for deprecation and removal of `loop.create_datagram_endpoint()`'s
|
||||
@@ -181,7 +177,6 @@ cdef class Loop:
|
||||
self._queued_streams = set()
|
||||
self._executing_streams = set()
|
||||
self._ready = col_deque()
|
||||
self._ready_len = 0
|
||||
|
||||
self.handler_async = UVAsync.new(
|
||||
self, <method_t>self._on_wake, self)
|
||||
@@ -440,7 +435,7 @@ cdef class Loop:
|
||||
self.handler_async.send()
|
||||
|
||||
cdef _on_wake(self):
|
||||
if ((self._ready_len > 0 or self._stopping) and
|
||||
if ((len(self._ready) > 0 or self._stopping) and
|
||||
not self.handler_idle.running):
|
||||
self.handler_idle.start()
|
||||
|
||||
@@ -481,8 +476,7 @@ cdef class Loop:
|
||||
if len(self._queued_streams):
|
||||
self._exec_queued_writes()
|
||||
|
||||
self._ready_len = len(self._ready)
|
||||
if self._ready_len == 0 and self.handler_idle.running:
|
||||
if len(self._ready) == 0 and self.handler_idle.running:
|
||||
self.handler_idle.stop()
|
||||
|
||||
if self._stopping:
|
||||
@@ -570,7 +564,6 @@ cdef class Loop:
|
||||
for cb_handle in self._ready:
|
||||
cb_handle.cancel()
|
||||
self._ready.clear()
|
||||
self._ready_len = 0
|
||||
|
||||
if self._polls:
|
||||
for poll_handle in self._polls.values():
|
||||
@@ -672,7 +665,6 @@ cdef class Loop:
|
||||
cdef inline _append_ready_handle(self, Handle handle):
|
||||
self._check_closed()
|
||||
self._ready.append(handle)
|
||||
self._ready_len += 1
|
||||
|
||||
cdef inline _call_soon_handle(self, Handle handle):
|
||||
self._append_ready_handle(handle)
|
||||
@@ -1412,7 +1404,7 @@ cdef class Loop:
|
||||
"""Create a Future object attached to the loop."""
|
||||
return self._new_future()
|
||||
|
||||
def create_task(self, coro, *, name=None, context=None):
|
||||
def create_task(self, coro, *, name=None, context=None, eager_start=None):
|
||||
"""Schedule a coroutine object.
|
||||
|
||||
Return a task object.
|
||||
@@ -1425,7 +1417,12 @@ cdef class Loop:
|
||||
created when no context is provided.
|
||||
"""
|
||||
self._check_closed()
|
||||
if PY311:
|
||||
if PY313:
|
||||
if self._task_factory is None:
|
||||
task = aio_Task(coro, loop=self, context=context, eager_start=eager_start)
|
||||
else:
|
||||
task = self._task_factory(self, coro, context=context, eager_start=eager_start)
|
||||
elif PY311:
|
||||
if self._task_factory is None:
|
||||
task = aio_Task(coro, loop=self, context=context)
|
||||
else:
|
||||
@@ -2061,6 +2058,9 @@ cdef class Loop:
|
||||
tr = TCPTransport.new(self, protocol, None, waiter, context)
|
||||
try:
|
||||
# libuv will make socket non-blocking
|
||||
# We are not detaching the PSO from the now-libuv-managed
|
||||
# FD here because of:
|
||||
# https://github.com/python/asyncio/pull/449
|
||||
tr._open(sock.fileno())
|
||||
tr._init_protocol()
|
||||
await waiter
|
||||
@@ -2073,6 +2073,15 @@ cdef class Loop:
|
||||
# up in `Transport._call_connection_made()`, and calling
|
||||
# `_close()` before it is fine.
|
||||
tr._close()
|
||||
# Fix for:
|
||||
# * https://github.com/MagicStack/uvloop/issues/645
|
||||
# * https://github.com/MagicStack/uvloop/issues/738
|
||||
# The underlying FD is closed in tr._close(), the owner of
|
||||
# `sock` must not get a chance to double-close the same FD
|
||||
# sometime later, because that FD may be reused by a new
|
||||
# connection under load. So we detach the PSO from the
|
||||
# already-closed FD here.
|
||||
sock.detach()
|
||||
raise
|
||||
|
||||
tr._attach_fileobj(sock)
|
||||
@@ -2314,7 +2323,9 @@ cdef class Loop:
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except BaseException:
|
||||
# See comments in create_connection() for more information
|
||||
tr._close()
|
||||
sock.detach()
|
||||
raise
|
||||
|
||||
tr._attach_fileobj(sock)
|
||||
@@ -2731,7 +2742,7 @@ cdef class Loop:
|
||||
return transport, protocol
|
||||
|
||||
def run_in_executor(self, executor, func, *args):
|
||||
if aio_iscoroutine(func) or aio_iscoroutinefunction(func):
|
||||
if aio_iscoroutine(func) or inspect_iscoroutinefunction(func):
|
||||
raise TypeError("coroutines cannot be used with run_in_executor()")
|
||||
|
||||
self._check_closed()
|
||||
@@ -2741,7 +2752,7 @@ cdef class Loop:
|
||||
# Only check when the default executor is being used
|
||||
self._check_default_executor()
|
||||
if executor is None:
|
||||
executor = cc_ThreadPoolExecutor()
|
||||
executor = cc_ThreadPoolExecutor(thread_name_prefix='uvloop')
|
||||
self._default_executor = executor
|
||||
|
||||
return aio_wrap_future(executor.submit(func, *args), loop=self)
|
||||
@@ -2910,7 +2921,7 @@ cdef class Loop:
|
||||
'the main thread')
|
||||
|
||||
if (aio_iscoroutine(callback)
|
||||
or aio_iscoroutinefunction(callback)):
|
||||
or inspect_iscoroutinefunction(callback)):
|
||||
raise TypeError(
|
||||
"coroutines cannot be used with add_signal_handler()")
|
||||
|
||||
|
||||
Reference in new issue
Block a user