Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Lib/concurrent/interpreters/_queues.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Cross-interpreter Queues High Level Module."""

import pickle
import queue
import time
import weakref
Expand Down Expand Up @@ -225,7 +224,7 @@ def put(self, obj, block=True, timeout=None, *,
while True:
try:
_queues.put(self._id, obj, unboundop)
except QueueFull as exc:
except QueueFull:
if timeout is not None and time.time() >= end:
raise # re-raise
time.sleep(_delay)
Expand Down Expand Up @@ -260,7 +259,7 @@ def get(self, block=True, timeout=None, *,
while True:
try:
obj, unboundop = _queues.get(self._id)
except QueueEmpty as exc:
except QueueEmpty:
if timeout is not None and time.time() >= end:
raise # re-raise
time.sleep(_delay)
Expand All @@ -279,7 +278,7 @@ def get_nowait(self):
"""
try:
obj, unboundop = _queues.get(self._id)
except QueueEmpty as exc:
except QueueEmpty:
raise # re-raise
if unboundop is not None:
assert obj is None, repr(obj)
Expand Down
11 changes: 11 additions & 0 deletions crates/stdlib/src/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ mod syslog {

#[pyfunction]
fn openlog(args: OpenLogArgs, vm: &VirtualMachine) -> PyResult<()> {
if !vm.state.is_main_interpreter() {
return Err(vm.new_runtime_error("subinterpreter can't use syslog.openlog()"));
}
let logoption = args.logoption;
let facility = args.facility;
let ident = match args.ident.clone() {
Expand Down Expand Up @@ -116,6 +119,11 @@ mod syslog {
vm.audit("syslog.syslog", || (priority, msg.clone()))?;

if !host_syslog::is_open() {
if !vm.state.is_main_interpreter() {
return Err(vm.new_runtime_error(
"subinterpreter can't use syslog.syslog() until the syslog is opened by the main interpreter",
));
}
openlog(
OpenLogArgs {
facility: LOG_USER,
Expand All @@ -132,6 +140,9 @@ mod syslog {

#[pyfunction]
fn closelog(vm: &VirtualMachine) -> PyResult<()> {
if !vm.state.is_main_interpreter() {
return Err(vm.new_runtime_error("subinterpreter can't use syslog.closelog()"));
}
vm.audit("syslog.closelog", || ())?;

host_syslog::closelog();
Expand Down
12 changes: 6 additions & 6 deletions crates/vm/src/stdlib/_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,12 @@ pub(crate) mod _thread {
func: &ArgCallable,
vm: &VirtualMachine,
) {
let msg = func
.as_ref()
.repr(vm)
.ok()
.map(|repr| format!("Exception ignored in thread started by {}", repr.as_wtf8()));
vm.run_unraisable(exc, msg, vm.ctx.none());
let msg = func.as_ref().repr(vm).ok().map(|repr| {
let mut message = Wtf8Buf::from("Exception ignored in thread started by ");
message.push_wtf8(repr.as_wtf8());
vm.ctx.new_str(message)
});
vm.run_unraisable_with_message(exc, msg, vm.ctx.none());
}

fn run_thread(func: ArgCallable, args: FuncArgs, vm: &VirtualMachine) {
Expand Down
24 changes: 15 additions & 9 deletions crates/vm/src/vm/crossinterp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Interpreters do not share `PyObject` graphs. Shareable values are converted
//! to an interpreter-neutral payload and rebuilt in the destination.
// cspell:ignore unpickler
// cspell:ignore unpickler unmarshalled

#[cfg(not(feature = "threading"))]
use crate::protocol::BufferDescriptor;
Expand Down Expand Up @@ -351,17 +351,23 @@ impl SharedValue {
}

fn marshal_dumps(obj: &PyObject, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
let dumps = vm.import("marshal", 0)?.get_attr("dumps", vm)?;
let bytes = dumps.call((obj.to_owned(),), vm)?;
let bytes = bytes
.downcast::<PyBytes>()
.map_err(|_| vm.new_type_error("marshal.dumps() did not return bytes"))?;
Ok(bytes.as_bytes().to_vec())
let dump = || -> PyResult<Vec<u8>> {
let dumps = vm.import("marshal", 0)?.get_attr("dumps", vm)?;
let bytes = dumps.call((obj.to_owned(),), vm)?;
let bytes = bytes
.downcast::<PyBytes>()
.map_err(|_| vm.new_type_error("marshal.dumps() did not return bytes"))?;
Ok(bytes.as_bytes().to_vec())
};
dump().map_err(|cause| not_shareable_error_from(vm, "object could not be marshalled", cause))
}

fn marshal_loads(data: &[u8], vm: &VirtualMachine) -> PyResult {
let loads = vm.import("marshal", 0)?.get_attr("loads", vm)?;
loads.call((vm.ctx.new_bytes(data.to_vec()),), vm)
let load = || -> PyResult {
let loads = vm.import("marshal", 0)?.get_attr("loads", vm)?;
loads.call((vm.ctx.new_bytes(data.to_vec()),), vm)
};
load().map_err(|cause| not_shareable_error_from(vm, "object could not be unmarshalled", cause))
}

/// `_memoryview_from_xid`.
Expand Down
11 changes: 10 additions & 1 deletion crates/vm/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,16 @@ impl VirtualMachine {

#[cold]
pub fn run_unraisable(&self, e: PyBaseExceptionRef, msg: Option<String>, object: PyObjectRef) {
let msg = msg.map(|msg| self.ctx.new_str(msg));
self.run_unraisable_with_message(e, msg.map(|msg| self.ctx.new_str(msg)), object);
}

#[cold]
pub(crate) fn run_unraisable_with_message(
&self,
e: PyBaseExceptionRef,
msg: Option<PyStrRef>,
object: PyObjectRef,
) {
let write_original = || {
let msg = msg.as_ref().map(|msg| msg.to_string_lossy());
self.write_unraisable_to_stderr(&e, msg.as_deref(), &object);
Expand Down
Loading