[Twisted-web] using asynqueue as part of twisted application

Drew Smathers drew.smathers at gmail.com
Wed Nov 26 11:51:50 EST 2008


On Tue, Nov 25, 2008 at 7:32 PM, Martin Bright <Martin.Bright at casero.com> wrote:
> The only way I have ever successfully used the wonderful Asynqueue module in
> a twisted application (using twistd) is by calling
>
>
>
> reactor.callWhenRunning(srvc.startup)
>
>
>
> where 'srvc' is a twisted.application.service object, and 'startup' is a
> function in which the queue is instantiated.
>
>


I have nil experience with Asynqueue, but you shouldn't have to
directly interact with the reactor to start a service.

>
> Is there a more obvious way?
>
>

The "obvious way" depends on the application.  If you're writing a
simple client application you might try something like this:

...
if __name__ = '__builtin__': # run with twistd -y
    from twisted.application import service
    application = service.Application('foo')
    svc = ... # Initialize asyncqueue service
    ...
    svc.setServiceParent(application)

This might be more than you need for your application, but I would
suggest also reading about Twisted application plugins:

http://twistedmatrix.com/projects/core/documentation/howto/tap.html


>
> Simply composing an object with a member that is a queue does not seem to
> work. The queue has to be started only when the reactor is running, which
> kinda makes sense, but is difficult for a noobie like me to figure out.
>

If you want a function to be called when the reactor is running, then
what you've done is correct - reactor.callWhenRunning().  However,
this is not the normal way to start services.

Drew



More information about the Twisted-web mailing list