[Twisted-Python] twisted and functional programming idioms

Tristan Seligmann mithrandi at mithrandi.net
Wed Jul 9 21:42:21 EDT 2008


* Rodney D Price <rodprice at raytheon.com> [2008-07-09 19:26:44 -0600]:

> So if I wanted to do something similar in Twisted,
> my first inclination is to use callLater,
> 
> def heartbeat(reactor):
>     doSomething()
>     reactor.callLater(1, heartbeat, reactor)
> reactor.run()
> 
> But then my head starts hurting, because I keep thinking that I have
> to set up all the callbacks before I start the reactor.  This code
> sets callbacks at runtime.  Will that be a problem?

This code should work perfectly; there's nothing wrong with invoking
callLater while the reactor is running.

> P.S.  I know there's probably a function somewhere in Twisted to do
> this already, but I'm not asking how to do this particular thing.  I'm
> really asking if thinking in terms of recursion is a useful Twisted
> idiom.

LoopingCall is the already-implemented version of this. I'm not really
sure if thinking in terms of recursion is a useful Twisted idiom,
though. On the one hand, Python doesn't handle lots of recursion very
well; on the other hand, this isn't really Python function recursion.
-- 
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/20080710/06774ae6/attachment.pgp 


More information about the Twisted-Python mailing list