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

Segfault related to PyCall #15

Closed
kmsquire opened this issue Mar 20, 2013 · 4 comments
Closed

Segfault related to PyCall #15

kmsquire opened this issue Mar 20, 2013 · 4 comments

Comments

@kmsquire
Copy link
Contributor

I've been getting random julia segfaults recently. Nothing specifically reproducible, but in this case, it happened at the REPL on the command immediately after I interrupted a PyCall function:

julia> df = E.extract_db_info()
^CERROR: interrupt
 in pycall at /scratch1/tmp/kmsquire/.julia/PyCall/src/PyCall.jl:62
 in anonymous at /scratch1/tmp/kmsquire/.julia/PyCall/src/conversions.jl:136
 in extract_db_info at /scratch1/tmp/kmsquire/Studies/TCGA_data/patients/ExtractDbInfo.jl:52

julia> df = E.extract_db_info();
Segmentation fault (core dumped)

The core dump gives

Core was generated by `julia'.
Program terminated with signal 11, Segmentation fault.
#0  0x00002b7fe2244967 in PyObject_IsInstance (inst=0x73e96e0, cls=0x2b7fe259b580) at Objects/abstract.c:2959
2959                if (Py_EnterRecursiveCall(" in __instancecheck__")) {

Perhaps pycall needs to be atomic in this case, or something isn't getting cleaned up by my interruption?

@kmsquire
Copy link
Contributor Author

Actually, I can reproduce this particular error pretty well if I interrupt the same function in the same way. Let me know if you need/want a more specific test case, and I'll see what I can come up with.

@stevengj
Copy link
Member

I think the problem is that the ccall to Python is not atomic (with respect to interrupts). If you interrupt in the middle of a Python C API call, Python itself could be left in an inconsistent state, leading to a crash on subsequent call.

Unfortunately, there doesn't seem to be any way to do an atomic ccall right now in Julia. (It seems like a new sigatomic_ccall would need to be added, which performs a ccall within the JL_SIGATOMIC_BEGIN and JL_SIGATOMIC_END macros in julia.h.) Or am I missing something in Julia API?

@JeffBezanson, can you comment?

@JeffBezanson
Copy link

Yes, that would probably fix it. We should probably also expose @sigatomic begin ... end in the language.

@stevengj
Copy link
Member

There are additional subtleties in really doing this right. Python would prefer to have its own SIGINT handler that raises a KeyboardInterrupt exception in the Python code. And then if Python calls a Julia callback routine, the callback should catch SIGINT in the Julia way. So, one would really like to push and pop different signal handlers at every Julia/Python boundary. Urgh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants