Is there a way to send a signal (e.g. ^C, SIGTERM) to the process being run from the IDE?

I am running a Python script from within PyCharm (via IntelliJ IDEA).  It is a daemon, and I'd like to send it one of the following signals to allow it to gracefully shutdown and complete.  Is there a way to send a signal to the process being run or debugged within the IDE?

Using the Stop button appears to kill the process cold without a chance to release resources.

    signals = [
Comment actions Permalink
If it's a deamon as you say then there's no other way to send signal to it than using kill and passing deamon's pid. As such it's a plain shell command and I guess the best you can get is some support for running shell or issuing shell commands in PyCharm. For instance take a look at Tools->Open Terminal
Comment actions Permalink
What if it's not a daemon, just a regular script that should be given a chance to clean up? As Sarah said, hitting the stop button seems to kill the process immediately.

Somewhat related question, but the "Run with Coverage" option only seems to work when the script comes to a natural completion. I'd like to use it with a web server that runs indefinitely. When I hit the Stop button (intending to generate a coverage report), it just kills the server and doesn't produce the report.
Comment actions Permalink
Well, the difference between deamon and regular process is that in case of regular process IDE knows its PID whereas with deamon there could be a couple of forks before the deamon process is created so there's no easy way to establish deamon's PID. Taking this into account PyCharm could support sending signals to running script but not to deamon. I googled only one feature request pertaining to sending signals in JetBrains' products – So while technically this is possible it's rarely needed and thus not implemented.
As you mentioned coverage and web server you might be interested in this Stackoverflow question -
Comment actions Permalink
As it turns out, if I just run the script within the IDE rather than debugging it, using the stop button allows the script to clean up.  So at least I can see the cleanup logic get exercised, even if it is not exercised during debugging or available to breakpoints.

I would like to see the ability to send signals to a running script—I'll log a YouTrack issue suggesting that feature.

Please sign in to leave a comment.