Repository navigation
Can we read python class attribute without gil in Rust? #2716
|
Greetings, I'd like to stop a Rust loop from python side. Say we have a python class class Flag:
stop = False
f = Flag()In Rust we have a function that will be running for a long time. I wish that once I set fn func_take_long_time(py: Python, object: &PyAny) {
let stop_flag: &bool = // can we get the reference of `f.stop` as `&bool`?
while true {
if *stop_flag { break; }
// .. do some time critical work
}
} |
Replies: 1 comment 4 replies
|
No, this is not possible. Among other things, there is no However, what you may be able to do is to move setting the stop flag to Rust, by providing a method/function |
No, this is not possible. Among other things, there is no
&boolthat would change, since Pythonboolobjects are immmutable. Reassigningf.stop = Truesets the "stop" entry inf.__dict__to theTrueobject instead of theFalseobject.However, what you may be able to do is to move setting the stop flag to Rust, by providing a method/function
set_stop_flag()implemented in Rust. Then, you can set an actual Rustboolflag (well, probablyAtomicBool) and check it cheaply from Rust code.