I have a mainloop in my program's main thread (The mainloop is a DBusGMainLoop waiting for a disk I/O event), every time an event handler is called a new thread is dispensed for some file copying. The strange thing happens at this point. Suppose an event is called and thread 1 is started. Thread 1 blocks at the line 'return os.listdir(path)
' until a second event happens and consequently a second thread starts. Then the thread 1 will continue working fine but thread 2 blocks. I've also noticed that if I interrupt the mainloop by Ctrl-C both threads will work but obviously the main thread will stop waiting for events.
Can anyone give any hint for why this happens?
This code runs in my main function:
mainloop = gobject.MainLoop()
mainloop.run()
This is where the event handler starts a new thread:
agent = CopyingAgent(mount_point)
agent.start()
and this is the method in which the thread seems to block or something:
def sorted_listdir(self, path):
return sorted(os.listdir(path))