【问题标题】:glib main loop hangs after PopenPopen 后 glib 主循环挂起
【发布时间】:2013-07-31 19:31:26
【问题描述】:

我正在尝试构建一个脚本,以在另一个窗口变为活动状态时记录窗口标题。这是我目前所拥有的:

import glib
import dbus
from dbus.mainloop.glib import DBusGMainLoop

def notifications(bus, message):
    if message.get_member() == "event":
        args = message.get_args_list()
        if args[0] == "activate":
            print "Hello world"
            activewindow = Popen("xdotool getactivewindow getwindowname", stdout=PIPE, stderr=PIPE); 
            print activewindow.communicate()



DBusGMainLoop(set_as_default=True)

bus = dbus.SessionBus()
bus.add_match_string_non_blocking("interface='org.kde.KNotify',eavesdrop='true'")
bus.add_message_filter(notifications)

mainloop = glib.MainLoop()
mainloop.run()

但是,我的 Popen 调用显然有问题,glib 似乎吞下了这个错误。至少,这是 IRC 频道上的某个人告诉我的。当我删除 Popenactivewindow.communicate() 呼叫时,一切正常,我收到一条消息“Hello world!”每当我切换到新窗口时都会打印在外壳中。

使用Popencommunicate() 调用,脚本会打印一个“Hello world”并在此之后挂起。

有谁知道:

  • 如何获得正确的错误消息?
  • 我在Popen 通话中做错了什么?

提前致谢!

【问题讨论】:

    标签: python popen glib dbus


    【解决方案1】:

    我不能只评论...您尚未导入流程模块或其成员(Popen、PIPE)。

    【讨论】:

      猜你喜欢
      • 2011-12-06
      • 1970-01-01
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 2013-01-04
      • 2015-08-18
      • 1970-01-01
      相关资源
      最近更新 更多