a glib main loop for receiving signal in a single thread may block other threads?

View: New views
1 Messages — Rating Filter:   Alert me  

a glib main loop for receiving signal in a single thread may block other threads?

by 火猴 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm trying to write a simple demo to receive signal in a single thread
and I use the glib
main loop(the code of the demo is attached). However it seemed that
the thread running the glib main loop block other
threads. I add some logging statements in the main thread, but it just
output the log
one time and then nothing is logged out.

But when signal was received in the signal handler thread, the main
thread output the log
again and again only one time. And I use ps to watch the kernel
function on which the current
process is sleeping, found that the main thread is sleeping on futex_wait.
--------------------------------------------------------------------------------
  PID   LWP WCHAN                     CMD
 2989  2989 futex_wait                python try.py
 2989  2990 poll_schedule_timeout     python try.py
-------------------------------------------------------------------------------

The version of dbus-python I used is dbus-python-0.83.0 by Fedora.
Could anyone tell me what is the problem and how should I fix it ?

Forgive for my poor English.
Thanks.

hotforest

[try.py]

#!/usr/bin/python

import gobject
import dbus,dbus.mainloop.glib
import threading
import time

def notify_change_signal_handler(*args,**kwargs):
        print 'signal handler is invoked'

def listen_for_signal():
        dbus_loop=dbus.mainloop.glib.DBusGMainLoop()
        bus=dbus.SessionBus(mainloop=dbus_loop)
        #self,handler_function,signal_name=None,dbus_interface=None,bus_name=None,path=None,**keywords
        bus.add_signal_receiver(notify_change_signal_handler,signal_name="notify_change_signal",\
                        dbus_interface="com.curve.xe.xemft",bus_name="com.curve.xe",\
                        path="/com/curve/xe/xemft")
        main_loop=gobject.MainLoop()
        main_loop.run()

if __name__=='__main__':
        proxy=threading.Thread(target=listen_for_signal)
        proxy.start()
        while True:
                print 'main thread running...'
                time.sleep(2)



_______________________________________________
dbus mailing list
dbus@...
http://lists.freedesktop.org/mailman/listinfo/dbus