mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Detach during blocking Windows multiprocessing socket I/O (#9093)
Snapshot locked send buffers before waiting and preserve the host-captured Winsock error across VM reattachment. Assisted-by: OpenAI Codex: model identifier unavailable Co-authored-by: dot <dot@youknowone.org>
This commit is contained in:
1 parent
e09846b4eb
commit
10cb49430a
1 file changed
+9
-6
@@ -408,19 +408,22 @@ mod _multiprocessing {
|
||||
|
||||
#[pyfunction]
|
||||
fn recv(socket: usize, size: usize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
|
||||
let mut buf =
|
||||
host_multiprocessing::recv_socket(socket as host_multiprocessing::RawSocket, size)
|
||||
.map_err(|_| vm.new_last_os_error())?;
|
||||
let mut buf = vm
|
||||
.allow_threads(|| {
|
||||
host_multiprocessing::recv_socket(socket as host_multiprocessing::RawSocket, size)
|
||||
})
|
||||
.map_err(|error| error.to_pyexception(vm))?;
|
||||
buf.shrink_to_fit();
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn send(socket: usize, buf: ArgBytesLike, vm: &VirtualMachine) -> PyResult<core::ffi::c_int> {
|
||||
buf.with_ref(|b| {
|
||||
host_multiprocessing::send_socket(socket as host_multiprocessing::RawSocket, b)
|
||||
let buf = buf.borrow_buf_unlocked(vm)?;
|
||||
vm.allow_threads(|| {
|
||||
host_multiprocessing::send_socket(socket as host_multiprocessing::RawSocket, &buf)
|
||||
})
|
||||
.map_err(|_| vm.new_last_os_error())
|
||||
.map_err(|error| error.to_pyexception(vm))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user