Eclipse 是否可以温和地终止而不是使用 SIGKILL?
我在 Windows 上使用 Eclipse,并使用 PyDev 插件进行 Python 开发。 当我使用“运行”启动应用程序时,它会生成一个新的 Python (CPython) 实例。 当我使用“终止”按钮(红色方块)时,它会终止该进程。 但是,它似乎执行了 SIGKILL,因此我的关闭处理程序无法清理。
有没有办法让 Eclipse 发送 SIGTERM,或者从 Eclipse 控制台模拟键盘中断(ctrl-c)?
注意:我知道还有其他 Python IDE(例如 Komodo 或 Wing)可能会解决此问题,但我不打算切换此问题。
I'm using Eclipse on Windows, with the PyDev plugin for Python development. When I use 'Run' to start my application, it spawns a new Python (CPython) instance. When I use the 'terminate' button (red square), it kills the process. However, it appears to do a SIGKILL, so my shutdown handler is unable to clean up.
Is there any way to get Eclipse to send a SIGTERM, or simulate a keyboard interrupt (ctrl-c) from the Eclipse console?
Note: I'm aware there are other Python IDEs like Komodo or Wing that might solve this problem, but I'm not looking to switch over this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Eclipse 使用发送信号的 Java Process API。 这是本机 API,无法更改。 我假设您也尝试过安装 SIGKILL 的处理程序,但这不起作用。
因此,唯一的解决方案是编写一个小批处理文件,其中列出了进程并向其中之一发送 SIGTERM。 从命令提示符调用它。 如果您使用 Alt-Tab 切换到它,它几乎与在 Eclipse 内部进行切换一样舒适。
或者编写一个插件来调用批处理文件。
Eclipse uses the Java Process API which sends the signal. This is a native API and there is no way to change that. I assume that you've tried to install a handler for SIGKILL, too, and that didn't work.
Therefore, the only solution would be to write a small batch file which lists the processes and sends SIGTERM to one of them. Invoke that from a command prompt. If you use Alt-Tab to switch to it, it's almost as comfortable as doing it from inside Eclipse.
Or write a plugin to invoke batch files.
我查看了 Java 程序如何获得自己的进程ID?并想出了这个。
我意识到,如果您不希望将其打印出来用于生产,那么这并不理想,但如果您只是制作原型,那么它很方便。 或者您可以将其放在仅在调试时运行的 if 中。
I looked at How can a Java program get its own process ID? and came up with this.
I realize this isn't ideal if you don't want it printing this out for production but if you're just prototyping it's handy. Or you could put it inside an if that only runs if you're debugging.