[Twisted-Python] thread pool question

Tristan Seligmann mithrandi-twisted-python at mithrandi.za.net
Thu Mar 22 18:42:46 EDT 2007


* Rutt, Benjamin <Benjamin.Rutt at gs.com> [2007-03-22 18:03:29 -0400]:

> Still isn't working for me:
> 
> #!/usr/bin/env python
> from twisted.internet import reactor
> from twisted.internet import threads
> def aSillyBlockingMethod(x):
>     import time
>     time.sleep(2)
>     print x
> d = threads.deferToThread(aSillyBlockingMethod, "2 seconds have passed")
> d.addBoth(lambda _: reactor.stop())

reactor.run()

With the above line of code added to the end, this code behaves as
expected for me:

mithrandi at elvardein:~> time python foo.py
2 seconds have passed
python foo.py  0.27s user 0.06s system 14% cpu 2.385 total

-- 
mithrandi, i Ainil en-Balandor, a faer Ambar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20070323/9f372434/attachment.pgp 


More information about the Twisted-Python mailing list