JuliaPy / JuliaPy/PythonCall.jl

Python callback to a Julia function?

Đang mở
#474 11 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Julia
Star
1.1k
Fork
86
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
3

Mô tả

If I have a Julia function which takes a callback (artificial example here):

```julia
function caller(callback, arg_vector)
callback(arg_vector)
return nothing
end

outer_vector = [0]
caller(outer_vector) do inner_vector
inner_vector[1] = 1
end
@assert outer_vector[1] == 1
```

And I'd like to call it from Python - it seems not possible to do so? Ideally:

```python
outer_vector = np.array([0])
with jl.MyModule.caller(outer_vector) as inner_vector:
inner_vector[0] = 1
assert outer_vector[0] == 1
```

I have a Julia package that uses callbacks for various functions (for example, initializing arrays), and I'm trying to wrap it with a Python interface. Being able to zero-copy pass around numpy arrays is a godsend, but it seems that callbacks of the above type are not supported. Looking at the code I see the tests for "callback" are empty...

Is there some manual workaround I could use in my code instead of direct support for the above? Any way at all, as long as I can bury the boilerplate code in my Python wrappers so the end user can use the `with` statement.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.