Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 00:41
    messense synchronize #567
  • 00:39

    messense on main

    Fix clippy warning on Rust 1.53 (compare)

  • Jun 17 22:21

    konstin on main

    Support Aarch64 on OpenBSD Update Changelog OpenBSD-Aarch64 Python 3.8 sysc… and 1 more (compare)

  • Jun 17 22:21
    konstin closed #570
  • Jun 17 22:21
    konstin commented #570
  • Jun 17 22:16
    dkarama synchronize #570
  • Jun 17 22:16
    dkarama commented #570
  • Jun 17 16:56
    konstin commented #570
  • Jun 17 16:12
    dkarama synchronize #570
  • Jun 17 16:12
    dkarama commented #570
  • Jun 17 15:58
    dkarama opened #570
  • Jun 17 01:07

    messense on main

    Refactor `Target::get_platform_… Merge pull request #569 from me… (compare)

  • Jun 17 01:07
    messense closed #569
  • Jun 16 14:16
    messense opened #569
  • Jun 16 08:41
    messense synchronize #567
  • Jun 16 05:27
    messense review_requested #567
  • Jun 16 04:47
    messense synchronize #567
  • Jun 16 04:42

    messense on main

    Support i386 on OpenBSD Update Changelog Merge pull request #568 from dk… (compare)

  • Jun 16 04:42
    messense closed #568
  • Jun 16 02:37
    dkarama synchronize #568
Matthew Plant
@maplant
Fundamentally, I want to collect deltas and then AFTER the script has been executed use those to modify rust state

so I run a script python script from rust that has the lines

do_thing_1()
do_thing_2()

the result on the Rust side would be a vec![ Action::DoThing1, Action::DoThing2 ]

mejrs
@mejrs
yeah that sounds kind of like what i thought, the easiest way would be a mutable global in Rust then
probably a pyo3::once_cell::GILOnceCell
Matthew Plant
@maplant
Right. I was really hoping to do it in a more functional style, passing an object in but this should work fine. Scripts will never be run in parallel so it should work fine. But it always feel a bit wrong to do a lazy_static RefCell.
Thanks for all the help mejrs, I really appreciate it!
mejrs
@mejrs
well you can't have a global with a refcell in it because it's !Sync
and np 👍
You'd need to use a mutex in general if you want something like that, and pyo3's GILOnceCell in this situation in particular to avoid the possibility of deadlocking
Matthew Plant
@maplant
Ah, I did not actually know that restriction existed, although it makes sense. I don't think I've ever actually needed a global mutable before this
Evgeniy Dubovskoy
@DrJackilD

Hey guys. I'm trying to write a simple function with pyo3 and then pack it to the wheel. Here is the function:

use num_bigint::BigUint;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;

#[pyfunction]
fn product_rust(l: Vec<BigUint>) -> PyResult<BigUint> {
    match l.into_iter().reduce(|x, y| x * y) {
        Some(val) => Ok(val),
        None => Err(PyValueError::new_err("Calculation error"))
    }
}

But I've got the error:

6   | #[pyfunction]
    | ^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Result<BigUint, PyErr>`

Does anyone know, how to handle it?

mejrs
@mejrs
Are you using the 0.4 version of num-bigint?
Evgeniy Dubovskoy
@DrJackilD
@mejrs Yes, this one
mejrs
@mejrs
Pyo3 0.13.2 is not compatible with that; you have to use 0.3
0.4 will be supported with pyo3 0.14. if you are okay with using a git dependency you can do that and use 0.4 of num-bigint right now
Evgeniy Dubovskoy
@DrJackilD
Ah, got it. Thank you very much!
mejrs
@mejrs
No problem 😉
Eric Arellano
@Eric-Arellano
Hey, is there any noticeable overhead or downsides to using Python.allow_threads(||)? I have a few relatively trivial functions where I'm wondering if it's sensible to use
David Hewitt
@davidhewitt
You are unlocking & re-locking a global lock (and possibly allowing a thread context switch), so I'd expect some overhead. Imo for super trivial functions it's not worth it, though the boundary is mostly empirical.
1 reply
I'd generally only add allow_threads when I know the function is going to consume significant CPU time in Rust where another Python thread could be running, or where the function will itself get blocked on io, subprocesses, other mutexes etc
slhmy
@slhmy

Hello, I'm running the example code in Calling Python in Rust code.
I have all the rust things already, but after I ran cargo run.
It shows:

dyld: Library not loaded: @rpath/libpython3.8.dylib
  Referenced from: /Users/slhmy/Workplace/python/python-rust/target/debug/python-rust
  Reason: image not found
zsh: abort      cargo run

I know I can fix it by export LD_LIBRARY_PATH, but actually thing makes me confused is why it choose python3.8 ?
I tried switching version by anacoda or using alias python=..., none of them will effect the version in rust code.

David Hewitt
@davidhewitt
@slhmy pyO3 looks in your PATH to find python, you can control this using a virtualenv or you can override with PYO3_PYTHON env var
1 reply
This matters at compile time, not runtime
tktech
@tktech:tkte.ch
[m]
Do the pyo3-asyncio developers happen to drop by here every once in awhile? Wanted to bounce some ideas around that are probably better in discussion than an issue.
tktech
@tktech:tkte.ch
[m]
Hm, I'm probably missing something obvious. When you have a #[pyclass], in a method of that class, how does one get the Python instance of self?
I'm basically looking for self.getattr(). Something like: python_class.call_method1("add_callback", (self.getattr("callback_method"),));
Dirkjan Ochtman
@djc
you can take Py<Self> as the first argument
tktech
@tktech:tkte.ch
[m]
Really? Fantastic, thank you.
mejrs
@mejrs
Py<...> is basically a smart pointer to something on the python heap
mejrs
@mejrs
David Hewitt
@davidhewitt
mejrs
@mejrs
ah so their docs are just off
makes you feel grateful for rustdoc and rendering docs from source :)
Sanskar Jethi
@sansyrox
Hey everyone.
Can someone point me to the source of this book(https://pyo3.rs/v0.13.2/) ? I would like to contribute to a chapter but I am unable to find the github link for this.
mejrs
@mejrs
In the repo, guide folder
mejrs
@mejrs
4 replies
Sebastian Plamauer
@turbinenreiter

Hi!

I'm trying to create a pyclass, but one of the fields is a type from a 3rd party crate -> the trait IntoPyCallbackOutput<_> is not implemented for zbus::Connection

Is there an example that shows how I could implement the trait for this type?
Thanks!

mejrs
@mejrs
You cant
Sebastian Plamauer
@turbinenreiter

oh no

Is there any way then to have a pyclass that contains a field which comes from a different library?

mejrs
@mejrs
You cant implement traits on types if neither belongs to you
You can have it as a field, you just cant directly expose it
Sebastian Plamauer
@turbinenreiter
oh, so just remove the #[pyo3(get, set)]
that's fine, I only interact with the field on the Rust side
thanks
mejrs
@mejrs
No problem :)
Sanskar Jethi
@sansyrox
How can one extract the output of the function from the PyAny object? e.g. one of my python function returns a string but when calling from rust, it returns a PyAny object. How can I use the output string from it?
Or downcast if you want to convert to PyString
Aviram Hassan
@aviramha
If anyone is looking for speedups for msgpack, check out my new library - https://github.com/aviramha/ormsgpack
mejrs
@mejrs
it's nice to see examples of people using pyo3::ffi in the wild :)