Can I load and run modules inside threads....

groupstudy2001 at yahoo.co.uk groupstudy2001 at yahoo.co.uk
Mon Jun 26 18:23:05 EDT 2006


.... and is it a good idea???

I am thinking of writing a controlling module - call it a postmaster if
you will - that will start submodules and pass them work via queues -
one input queue per module. The modules will send their results back to
the postmaster via its queue. The postmaster will then read the
incoming message and, if necessary, pass it on to another thread.

The problem is that I want the submodules NOT to be known by or part of
the original module. So I have to load them as the need is seen,
probably by name, and tie them to queues. Can anyone see a problem with
this or some good way to do it?

Maybe,

modname = ....... #Module name a variable
exec("import %s as mod" % modname)
module_input_queue = Queue.Queue()
new_thread = mod.classname(
   my_queue, module_input_queue, parms)
new_thread.start()




More information about the Python-list mailing list