<html><body>On 08:32 pm, ellisonbg.net@gmail.com wrote:<br /><br />&gt;&gt;I am very curious about your 0.00001% case. &#160;Not that I don't believe such<br />&gt;&gt;cases exist, but in every case but one (twisted ticket #2545) the issue has<br />&gt;&gt;actually been a documentation problem with Twisted, where it wasn't clear<br />&gt;&gt;how to do something the "normal" way with Deferreds and such. &#160;I'd like to<br />&gt;&gt;know if there is another such doc bug we should be filing :).<br />&gt;<br />&gt;The cases I am thinking about is not an example of a doc bug. &#160;The<br />&gt;most relevant one is related to using Twisted in an interactive python<br />&gt;(really IPython most of the time) session. &#160;There are two difficulties<br />&gt;we keep running into:<br /><br />Hmm. &#160;I hope you're not the guy I talked to at PyCon (I didn't catch his/your name) because I'm about to feel very foolish repeating myself here, especially if at some point in the interim you responded to this and I didn't notice.<br /><br />&gt;1. &#160;The interactive python interpreter is a completely synchronous<br />&gt;universe - getting the reactor running in this context seems like a<br />&gt;hack. &#160;The only way I have seen this done is by running the reactor in<br />&gt;a different thread. &#160;The problem with this is that it is inevitable<br />&gt;that you end up wanting to do things with Deferreds in the main thread<br />&gt;where user code is running. &#160;But, as I understand it, Twisted is not<br />&gt;thread safe, so at that point, you are playing with (threaded) fire.<br /><br />IPython's shell is not the same as the standard Python interpreter. &#160;It's already its own program and therefore has a fair amount of freedom in what it does with user input.<br /><br />Run "python -m twisted/conch/stdio" for an example of an interactive session that is held in a non-blocking way. &#160;Not blocking in the code *doesn't* mean not blocking for the user - it just means having the option not to block.<br /><br />&gt;2. &#160;Users expect certain things in an interactive python session that<br />&gt;don't mesh well with Twisted and the asynchronous universe:<br /><br />This is _exactly_ the documentation issue I was talking about :).<br /><br />&gt;&gt;&gt;&gt;psi = computeWavefunctionForHydrogen()<br />&gt;&gt;&gt;&gt;psi.getEnergy(1)<br />&gt;-13.6<br />&gt;# here the user looks at the energy (a human if statement) and decides<br />&gt;if they actually want to<br />&gt;# make the following plot. &#160;If the answer were not -13.6, they would<br />&gt;not make the plot.<br />&gt;&gt;&gt;&gt;plot(psi.getState(1))<br />&gt;<br />&gt;Even if you could get the reactor running in an interactive python<br />&gt;session it would be crazy to have to write something like (in an<br />&gt;interactive session):<br />&gt;&gt;&gt;&gt;d = computeWavefunctionForHydrogen()<br />&gt;&gt;&gt;&gt;def printAndPlot(psi, n):<br />&gt;&gt;&gt;&gt; &#160; &#160; print psi.getEnergy(n)<br />&gt;&gt;&gt;&gt; &#160; &#160; if abs(psi.getEnergy(n) - (psi.getEnergy(n)) &lt; 1.0e-4:<br />&gt;&gt;&gt;&gt; &#160; &#160; &#160; &#160; plot(psi.getState(n))<br />&gt;&gt;&gt;&gt;d.addCallback(printAndPlot, 1)<br /><br />Here's a screenshot of an interactive session using the command above:<br /><br />http://twistedmatrix.com/users/glyph/images/content/screenshots/psi-energy.png<br /><br />Unfortunately it doesn't animate, but there is a 1-second pause between "&lt;Deferred #0&gt;" and "Deferred #0 called back:". &#160;It's a bit crude since it is "deferred-oriented" right now, rather than result oriented, but a few clever implementation tricks could easily eliminate the distinction (like the "_.result" line).<br /><br />Is that the kind of user-interaction you want?<br /></body></html>