Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfaulting Threaded code #325

Closed
bryaan opened this issue Jun 8, 2023 · 1 comment
Closed

Segfaulting Threaded code #325

bryaan opened this issue Jun 8, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@bryaan
Copy link

bryaan commented Jun 8, 2023

PythonCall

When running the following script you will get a segfault. Please help debug as it seems to be a problem with this lib and async methods. Seems to work when @Spawn is changed to @async but that causes it to execute sequentially, which is another issue.

using PythonCall

Web3 = pyimport("web3")

web3async = Web3.AsyncWeb3(Web3.AsyncHTTPProvider("https://mainnet.infura.io/v3/b048b4d49aad428babc12c0eb65dcdc9"))

while true
    @time for _ in range(1, 10)
        Threads.@spawn begin
            blockCoro = web3async.eth.get_block(17418534)
            # block = asyncio_run(blockCoro)
            # @show block 
        end
    end
    sleep(1)
end

wait()
[73021] signal (11.2): Segmentation fault: 11
@bryaan bryaan added the bug Something isn't working label Jun 8, 2023
@cjdoris
Copy link
Collaborator

cjdoris commented Jun 15, 2023

PythonCall is not thread safe. You can only call Python from the main thread: https://cjdoris.github.io/PythonCall.jl/dev/faq/#Is-PythonCall/JuliaCall-thread-safe?

If you want to use multithreading you have to do that from Python.

@cjdoris cjdoris closed this as completed Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants