Skip to content

KeyboardInterrupt support / SIGINT handler #211

Open
@tkf

Description

@tkf

Currently PyJulia does not support KeyboardInterrupt. That is to say, in long-running Python and Julia computation, there is no way to terminate a sub-computation by catching KeyboardInterrupt as done in normal Python programming.

Aside: Recommended way to cancel current input in REPL is to use IPython 7.0 or above. Ctrl-C would cancel the input without causing SIGINT.

This problem is previously mentioned in: #189, #185 (comment)

What follows is a summary of my understanding:

When PyJulia is initialized, libjulia takes over all signal handling. I couldn't find a way to disable this behavior. Julia documentation mentions that "Julia requires a few signal to function property." so it probably would not have something like Py_InitializeEx to initialize libjulia without installing signal handlers anytime soon.

What would be more easily achievable is to let Julia translate SIGINT to InterruptException and then let PyCall to translate it to Python's KeyboardInterrupt. I have implemented it in JuliaPy/PyCall.jl#574 but it introduced a bug which is hard to track. I reported it in Julia: JuliaLang/julia#29498. Note that this strategy is not perfect because long-running pure-Python computation or I/O cannot respond to SIGINT. If Julia implements some kind of signal handling JuliaLang/julia#14675 then maybe we can call PyErr_SetInterrupt (which does not need GIL) from it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions