简体   繁体   English

使用 GLib 从 Python 子进程捕获信号

[英]Catching signal from Python child process using GLib

I'm trying to control the way my cursor looks during certain points of my program execution.我试图控制我的 cursor 在程序执行的某些点的外观。 To be specific, I want it to be a "spinner" when a Python script is executing, and then a standard pointer when it's done executing.具体来说,我希望它在执行 Python 脚本时成为“微调器”,然后在执行完成时成为标准指针。 Right now, I have a leave-event-notify callback in Glade that changes the spinner when it leaves a certain area, but this is non-ideal since the user might not know to move the cursor and the cursor doesn't accurately represent the state of the program.现在,我在 Glade 中有一个 leave-event-notify 回调,当它离开某个区域时会更改微调器,但这并不理想,因为用户可能不知道移动 cursor 和 cursor 不能准确表示state 的程序。

I have my Python program signalling SIGUSR1 at the end of execution.我的 Python 程序在执行结束时发出 SIGUSR1 信号。 I am spawning the Python script from a C file using GLib's g_spawn_async_with_pipes .我正在使用 GLib 的g_spawn_async_with_pipes从 C 文件生成 Python 脚本。 Is there any way to catch a signal from the child process that this creates?有什么方法可以从创建的子进程中捕获信号吗? Thanks!谢谢!

Pass the G_SPAWN_DO_NOT_REAP_CHILD flag to g_spawn_async_with_pipes() and then call g_child_watch_add() to get a notification when your Python subprocess exits.G_SPAWN_DO_NOT_REAP_CHILD标志传递给g_spawn_async_with_pipes() ,然后在 Python 子进程退出时调用g_child_watch_add()以获取通知。 You don't need to bother with SIGUSR1 if the process exits when it's done.如果进程在完成后退出,您无需担心SIGUSR1

It's a bit hard to provide a more specific answer unless you post a minimal reproducible example of your code.除非您发布代码的最小可重现示例,否则很难提供更具体的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM