[Twisted-Python] deferToThread and thread ID

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 purposes. Is there any way to do this?
Here is a piece of my script:
... d1 = getPage('http://www.google.com/') d1.addCallback(printContents)
d = threads.deferToThread(largeFibonacciNumber) d.addCallback(fibonacciCallback)
if __name__ == '__main__': run() reactor.run()
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?
Thanks --- Masetto

On 05:23 pm, masetto4ever@gmail.com wrote:
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 purposes. Is there any way to do this?
deferToThread uses the regular Python threading APIs, so you can too. In this case, thread.get_ident() should give you what you're looking for.
Jean-Paul
participants (2)
-
exarkun@twistedmatrix.com
-
masetto scarface