Problem with queues and gobject event loop

R

Roman Kapl

Why does not this snipplet work?
-----------------------------------------------------------------
from job import JobQueue
import Queue
import threading
import gobject
q=JobQueue()
def worker():
print "Worker waiting"
q.get()
print "Got job!"

if __name__ == "__main__":
t = threading.Thread(target=worker)
t.start()
q.put(1)
loop = gobject.MainLoop()
loop.run()
---------------------------------------------------------------------
It blocks indefinitely on the q.get() in the worker thread. When I
remove the the gobject main loop call, the code works fine and worker
thread gets to the print "Got job!" statement. This is just simplified
example to show the weird behaviour, otherwise I am trying to receive
messages via DBus and schedule jobs for another thread(I am a DBus
server). So is it a bug, my mistake or just simply queues can't be
used in combination with gobject main loop? Can I use dbus without
main loop(since I really don't need it, but I couldn't find any
example how to get rid of it.

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top