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

Stopping server with Ctrl-C or signals does not work with Jython or IronPython #14

Closed
pekkaklarck opened this issue Mar 5, 2014 · 2 comments
Assignees
Labels
Milestone

Comments

@pekkaklarck
Copy link
Member

With Python Ctrl-C stops the server fully. With Jython and IronPython stopping is initiated but the process doesn't return and there is a traceback on the console. The server exits if it is ever used again.

The problem is caused by differences in handling exceptions raised by signal handlers. With Python the exception we use breaks the loop in serve_forever, but with Jython and IronPython it is just logged to console. A fix is removing this hack solution and using timeout in handle_request inside the main loop.

@pekkaklarck pekkaklarck added this to the 1.0.1 milestone Mar 5, 2014
@pekkaklarck pekkaklarck added the bug label Mar 5, 2014
@pekkaklarck pekkaklarck self-assigned this Mar 12, 2014
@pekkaklarck
Copy link
Member Author

In addition to Ctrl-C, this problem also prevented using signals to stop the server.

@fengzmg
Copy link

fengzmg commented Jul 9, 2015

I was facing similar problem before in Jython. This is how I get it resolved.

First, register a signal handler in your Jython script by:

import signal
def intHandler(signum, frame):
    print "Shutting down.."
    System.exit(1)

# Set the signal handler
signal.signal(signal.SIGINT, intHandler)
signal.signal(signal.SIGTERM, intHandler)

This will register the signal handler for the Jython script to handle CTRL+C keyboard input.

However, the default console class org.python.util.JLineConsole treats ctrl+C as a normal character inputs.

So, Secondly - need to change the python.console to an alternative console class org.python.core.PlainConsole by either change the Jython property:

python.console=org.python.core.PlainConsole

or add the jvm argument:

-Dpython.console=org.python.core.PlainConsole

This will help you to shutdown the program after CTRL+C is pressed.

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

No branches or pull requests

2 participants