使用GLib从Python子进程捕获信号 [英] Catching signal from Python child process using GLib

查看:90
本文介绍了使用GLib从Python子进程捕获信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试控制程序执行过程中某些时刻的光标外观.具体而言,我希望它成为纺纱厂".在执行Python脚本时执行,然后在执行完毕后使用标准指针.现在,我在Glade中有一个Leave-event-notify回调,它在离开特定区域时更改微调器,但这是不理想的,因为用户可能不知道移动游标并且游标不能准确表示程序的状态.

I'm trying to control the way my cursor looks during certain points of my program execution. 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. 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.

我的Python程序在执行结束时发出SIGUSR1信号.我正在使用GLib的 g_spawn_async_with_pipes 从C文件生成Python脚本.有没有办法从子进程中捕获由此创建的信号?谢谢!

I have my Python program signalling SIGUSR1 at the end of execution. I am spawning the Python script from a C file using GLib's g_spawn_async_with_pipes. Is there any way to catch a signal from the child process that this creates? Thanks!

推荐答案

G_SPAWN_DO_NOT_REAP_CHILD 标志传递到 g_spawn_async_with_pipes(),然后调用 g_child_watch_add()在您的Python子进程退出时获得通知.如果该过程完成后退出,则无需担心 SIGUSR1 .

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. You don’t need to bother with SIGUSR1 if the process exits when it’s done.

除非您发布代码的最小可复制示例,否则很难提供更具体的答案.

It’s a bit hard to provide a more specific answer unless you post a minimal reproducible example of your code.

这篇关于使用GLib从Python子进程捕获信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆