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

Python REPL: KeyboardInterrupt stops working after import #74

Closed
nrontsis opened this issue Oct 31, 2022 · 6 comments · Fixed by #75
Closed

Python REPL: KeyboardInterrupt stops working after import #74

nrontsis opened this issue Oct 31, 2022 · 6 comments · Fixed by #75
Labels
bug Something isn't working

Comments

@nrontsis
Copy link

nrontsis commented Oct 31, 2022

As described in the title, KeyboardInterrupt stops working after importing the basic example of this repo.

How to reproduce:

Using the Dockerfile below run:

$ docker build -t jnumpy .
$ docker run -it jnumpy python

and then

Python 3.9.15 (main, Oct 25 2022, 05:49:37)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>     <- Ctrl-C triggers KeyboardInterrupt
KeyboardInterrupt
>>> import basic
Can not find julia.
... [Installing julia]
>>>    <- Ctrl-C does not trigger KeyboardInterrupt anymore

Dockerfile:

FROM python:3.9-slim
RUN apt-get update
RUN apt-get install -y git gpg
RUN pip install julia-numpy jill
RUN git clone https://github.com/Suzhou-Tongyuan/jnumpy
ENV PYTHONPATH=/jnumpy/demo
@johnnychen94
Copy link
Member

johnnychen94 commented Nov 1, 2022

Weird. I could only reproduce this on the first try.

The only place I see try...catch through the downloading call stack is https://github.com/johnnychen94/jill.py/blob/cfc14a6a700172833487bdc1ef2204b14d4cb88a/jill/download.py#L50-L69, but it's limited to network exceptions.

wget.download directly calls urllib.request.urlretrieve. Maybe it's something there since it's a legacy interface?

@songjhaha
Copy link
Member

@johnnychen94
I think it's a jnumpy's issue, I could reproduce in my compute.

In [1]: import basic # success
In [2]: import wget
In [3]: wget.download("https://wrongURL")
# <- Ctrl-C does not work here

My envrionment:

os: win10
python: 3.10

@johnnychen94
Copy link
Member

johnnychen94 commented Nov 1, 2022

I assume you're saying it's a wget issue?

In [1]: import wget

In [2]: wget.download("https://hi")
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C
KeyboardInterrupt

This Python package isn't maintained since 2015, so maybe this issue is a good reason to drop wget-python in jill.

@songjhaha
Copy link
Member

Other task also fail to use KeyboardInterrupt too, so maybe something of jnumpy breaks the signal handling

@songjhaha
Copy link
Member

songjhaha commented Nov 1, 2022

Register a signal handler may solve this problem, but I could not find where jnumpy breaks this yet, and not sure if other signal handler works fine. @thautwarm could you have a look?

import time
import signal

default_sigint_handler = signal.getsignal(signal.SIGINT)
print(default_sigint_handler) # <built-in function default_int_handler>

import jnumpy as jnp
jnp.init_jl()

print(signal.getsignal(signal.SIGINT)) # still <built-in function default_int_handler> ???

signal.signal(signal.SIGINT, default_sigint_handler) # if we don't call this, the Ctrl-C would not work below

# Ctrl-C works here
for i in range(10):
    print(i)
    time.sleep(1)

ps: it's weird. the code above works fine in my archlinux system, but fails in my win10 system :(

@songjhaha songjhaha added the bug Something isn't working label Nov 1, 2022
@songjhaha
Copy link
Member

We need to disable the signal handle of julia in python mode:

SessionCtx.JULIA_START_OPTIONS = ["--handle-signals=no", jl_opts_proj, *jl_opts]

This solves the problem.

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

Successfully merging a pull request may close this issue.

3 participants