Putting function references in a Queue

Bryan Olson fakeaddress at nowhere.org
Tue Aug 9 19:46:22 EDT 2005


Richard Townsend wrote:
 > I've been experimenting putting a reference to a function into a Queue
 > object and was wondering what actually gets put in the Queue - is it the
 > function's code object?

It's a Python-internal-reference-thingy.

 > If I read from the Queue in a different module, it appears that I don't
 > need to import the module that defines the function - or any module 
that it
 > uses - is this generally true, or are there some conditions to be 
aware of?

Yes, generally true. It has to be implemented somewhere in the
process; the reference-thingy knows where.

 > The scenario I'm working on has child threads doing some tasks and then
 > sending back tuples (done, function, args, kwargs) via the Queue, to be
 > called in the main thread. The Python code is ultimately embedded in a
 > C/Motif app.

I think that's a good thing to do. The tricky part is getting an
event loop to wait on both the queue and other kinds of events.
Periodic polling works, but kind of sucks.

What's the 'done' argument? A lock maybe?


-- 
--Bryan



More information about the Python-list mailing list