_asyncio rust impl

This commit is contained in:
Jeong YunWon
2026-01-24 09:24:27 +09:00
committed by Jeong, YunWon
parent 850a0a7847
commit d8fa1b4366
7 changed files with 2722 additions and 126 deletions

View File

@@ -730,8 +730,6 @@ class CFutureTests(BaseFutureTests, test_utils.TestCase):
evil = gc.get_referents(_asyncio)
gc.collect()
# TODO: RUSTPYTHON - _asyncio delegates to Python impl, no true C behavior
@unittest.expectedFailure
def test_callbacks_copy(self):
# See https://github.com/python/cpython/issues/125789
# In C implementation, the `_callbacks` attribute

View File

@@ -963,8 +963,6 @@ class TestSSL(test_utils.TestCase):
asyncio.wait_for(client(srv.addr),
timeout=support.SHORT_TIMEOUT))
# TODO: RUSTPYTHON - BrokenPipeError in connection_lost callback
@unittest.expectedFailure
def test_start_tls_server_1(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE

View File

@@ -728,9 +728,6 @@ class TestAsyncExitStack(TestBaseExitStack, unittest.IsolatedAsyncioTestCase):
stack.push_async_exit(cm)
self.assertIs(stack._exit_callbacks[-1][1], cm)
@unittest.expectedFailure # TODO: RUSTPYTHON; - no _asyncio module, pure Python Task adds extra frame
def test_exit_exception_traceback(self):
return super().test_exit_exception_traceback()
class TestAsyncNullcontext(unittest.IsolatedAsyncioTestCase):

File diff suppressed because it is too large Load Diff

View File

@@ -92,6 +92,10 @@ pub struct VirtualMachine {
pub async_gen_firstiter: RefCell<Option<PyObjectRef>>,
/// Async generator finalizer hook (per-thread, set via sys.set_asyncgen_hooks)
pub async_gen_finalizer: RefCell<Option<PyObjectRef>>,
/// Current running asyncio event loop for this thread
pub asyncio_running_loop: RefCell<Option<PyObjectRef>>,
/// Current running asyncio task for this thread
pub asyncio_running_task: RefCell<Option<PyObjectRef>>,
}
#[derive(Debug, Default)]
@@ -190,6 +194,8 @@ impl VirtualMachine {
c_stack_soft_limit: Cell::new(Self::calculate_c_stack_soft_limit()),
async_gen_firstiter: RefCell::new(None),
async_gen_finalizer: RefCell::new(None),
asyncio_running_loop: RefCell::new(None),
asyncio_running_task: RefCell::new(None),
};
if vm.state.hash_secret.hash_str("")

View File

@@ -237,6 +237,8 @@ impl VirtualMachine {
c_stack_soft_limit: Cell::new(VirtualMachine::calculate_c_stack_soft_limit()),
async_gen_firstiter: RefCell::new(None),
async_gen_finalizer: RefCell::new(None),
asyncio_running_loop: RefCell::new(None),
asyncio_running_task: RefCell::new(None),
};
ThreadedVirtualMachine { vm }
}

View File

@@ -178,8 +178,10 @@ fn already_warned(
Some(version_obj)
if version_obj.try_int(vm).is_ok() || version_obj.is(&filters_version) =>
{
let already_warned = registry.get_item(key.as_ref(), vm)?;
if already_warned.is_true(vm)? {
// Use .ok() to handle KeyError when key doesn't exist (like Python's dict.get())
if let Ok(already_warned) = registry.get_item(key.as_ref(), vm)
&& already_warned.is_true(vm)?
{
return Ok(true);
}
}