On 2 May 2007 09:41:56 -0700, rh0dium <[EMAIL PROTECTED]> wrote:
> On May 2, 8:25 am, Gary Herron <[EMAIL PROTECTED]> wrote:
> > rh0dium wrote:
> > >> This is far more work than you need. Push an (args, kwargs) tuple into
> > >> your arguments queue and call self.function(*args, **kwargs).
> >
> > > No see I tried that and that won't work.
> >
> > Won't work?  How does it fail?> I'm assuming what you are referring to is 
> > this (effectively)
> >
> > > Q.put(((),{a:"foo", b:"bar}))
> >
> > > input = Q.get()
> > > self.function( *input[0], **input[1])
> >
> > > This will obviously fail if several conditions aren't met - hence the
> > > kludge.  Am I missing something here?
> >
> > Obviously?  Conditions?  What conditions?
> >
> > We do things like this constantly, and in fact, it *does* work.
> >
> > Please tell us how it fails, or what is unsatisfactory about it.
> >
> > Gary Herron
>
> Good - It looks like I am the one who is clueless..
>
> If I do this:
>
> def funcA(input):
>    pass
>
> Then I run the code
> for x in range(lod):myQ.put(random.random())
> myQ.put(None)
> a=WorkerB(requestQ=myQ, function=funcA).start()
>
> This will fail because there isn't an input[1]
>


Thats because you put the wrong value into the arguments queue.
For this use case, we define the arguments queue as being a source of 2-tuples,
with an argument list and a kwargs dict. So you have to do:

for x in range(lod):
    myQ.put((random.random(), {}))

(don't be afraid of indentation and newlines - I started to modify
your source to provide a working example and got frustrated
reformatting it so I could read it)

Since you've now defined the external interface for your system (pass
it a queue of argument, kwargs tuples and a callable) it's the
responsibility of the caller to correctly satisfy that interface.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to