[Twisted-Python] when to use callInThread?

Hi all
I have a function like:
def longQuery(xxx)
this function will be invoked simultaneously (it means multiple thread environment) and this function may take a while to complete.
so my question is whether i should use reactor.callInThread to take benefit from non blocking
or use deferred object ?
It seems that deferred object doens't use threads.
Regards
GELIN YAN

Why is it invoked in a multithread environment? You can use deferToThread, which gives you a deferred which runs in a thread.
cheers lvh

Hi Ivh
I just finished the reading of deterToThread Part. I think it is what i need. Thank you anyway..
Regards
gelin yan
On Sat, May 7, 2011 at 5:49 PM, Laurens Van Houtven _@lvh.cc wrote:
Why is it invoked in a multithread environment? You can use deferToThread, which gives you a deferred which runs in a thread.
cheers lvh
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

On Sat, May 07, 2011 at 04:49:22PM +0800, Dfgqq Dfgqq wrote:
Hi all
I have a function like:
def longQuery(xxx)
this function will be invoked simultaneously (it means multiple thread environment) and this function may take a while to complete.
so my question is whether i should use reactor.callInThread to take benefit from non blocking
briefly you should use `callInThread` in two cases: when your code does some long computation and when you use some libraries that do network communication in a blocking manner.
or use deferred object ?
It seems that deferred object doens't use threads.
http://twistedmatrix.com/documents/current/core/howto/gendefer.html#auto2
If `longQuery` is a DB query you should look at twisted.enterprise.adbapi
http://twistedmatrix.com/documents/current/core/howto/rdbms.html
m.
participants (3)
-
Dfgqq Dfgqq
-
Laurens Van Houtven
-
Marco Giusti