<br><br><div class="gmail_quote">On Wed, Oct 24, 2012 at 7:43 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><div class="im">
> I don't know, I hope someone with an expertise in Twisted can tell us.<br>
><br>
> But I would imagine that they don't have this particular problem, as it<br>
> should be related only to coroutines and schedulers that run them.  I.e.<br>
> it's a problem when you run some code and may interrupt it.  And you can't<br>
> interrupt a plain python code that uses callbacks without yields and<br>
> greenlets.<br>
<br>
</div>Well, but in the Twisted world, if a cleanup callback requires more<br>
blocking calls, it has to spawn more deferred callbacks. So I think<br>
they *do* have the problem, unless they don't have a way at all to<br>
constrain the total running time of an action involving cascading<br>
callbacks. Also, they have inlineCallbacks which does use yield.<br></blockquote><div><br>Deferreds don't do anything to prevent blocking. They're just a nice abstraction for callbacks. And yes, if you call 1000 functions that do lots of CPU in a row, that will keep other stuff from happening.<br>
<br>However, consider how a timeout works: the event loop notices enough time has passed, and so calls some code that tells the Deferred to cancel its operation. So you're *not* adding the cancellation operations to the stack of the original operation, you're starting from the event loop. And so timeouts are just normal event loop world, where you need to be careful not to do to much CPU-intensive processing in any given call, and you can't call blocking system calls (except using a thread).<br>
<br>Of course, you can't timeout a function that's just looping using CPU, or a blocking system call, and so code needs to be structured to deal with this, but that's a different issue.<br></div></div>