[Twisted-Python] deferToThread and thread ID

masetto scarface masetto4ever at gmail.com
Thu Dec 3 12:23:28 EST 2009

Hi all,

Last week i've started to study (and love :P) Twisted .
Well, just for didactical purpose i've written a little script which
download a web page (getPage) and calculate a long Fibonacci number within a
deferToThread and it works perfectly.
I would like to see the different threads id of the two operations (download
a web page and the calculation of the number), always for didactical
Is there any way to do this?

Here is a piece of my script:

    d1 = getPage('http://www.google.com/')

    d = threads.deferToThread(largeFibonacciNumber)

if __name__ == '__main__':

Is it possibile to print within these functions their thread id (PID is
always the same :P)?
Something like:

Executing printContents func
PID: 1234
Thread ID: x

Executing Fibonacci func
PID: 1234
Thread ID: y

I suppose it works in this way, isn't it?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20091203/1e99d448/attachment.htm 

More information about the Twisted-Python mailing list