[Twisted-Python] blocking code alongside with Twisted
Shuai Lin
linshuai2012 at gmail.com
Sat Sep 1 00:04:22 MDT 2012
Thanks for the quick reply. I don't need Ampoule, since the tasks are
simply calling some libreoffice api to convert documents to pdf format, but
thank you all the same!
On Sat, Sep 1, 2012 at 1:53 PM, Glyph <glyph at twistedmatrix.com> wrote:
>
> On Aug 31, 2012, at 10:30 PM, Shuai Lin <linshuai2012 at gmail.com> wrote:
>
> > Hi all,
> >
> > My server mainly consists of two modules:
> > -- http api handling (using twisted)
> > -- backend blocking tasks
> >
> > The backend tasks have to block, because I have to call some
> third-party API, which is always blocking. What's more, since the
> third-party api call is blocking, I plan to use a thread pool to implement
> a connection pool.
> >
> > My question is: Is it ok to use twisted in this manner? i.e. I just
> run `reactor.run()' in the main thread (to handle the http api request),
> and the rest of the program is blocking -- and intrinsically not related
> to twisted.
> >
> > Any suggestion is appreciated. Thanks!
>
> Sure, this is fine. This is why the reactor has callInThread() after all
> :). It may also make sense to use something like Ampoule <
> https://launchpad.net/ampoule> if the backend tasks are CPU intensive as
> well, and you want multi-core parallelism.
>
> -glyph
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20120901/594374b2/attachment.html>
More information about the Twisted-Python
mailing list