<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for krondo</title>
	<atom:link href="http://krondo.com/blog/?feed=comments-rss2" rel="self" type="application/rss+xml" />
	<link>http://krondo.com</link>
	<description>The website of Dave Peticolas</description>
	<lastBuildDate>Fri, 03 Sep 2010 01:53:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>Comment on An Introduction to Asynchronous Programming and Twisted by dave</title>
		<link>http://krondo.com/?p=1682&#038;cpage=1#comment-2942</link>
		<dc:creator>dave</dc:creator>
		<pubDate>Fri, 03 Sep 2010 01:53:44 +0000</pubDate>
		<guid isPermaLink="false">http://krondo.com/blog/?p=1682#comment-2942</guid>
		<description>Yes, addBoth is very handy. But one thing I&#039;ve learned teaching (I also teach Python to new programmers): don&#039;t try to introduce too many new things at once :)</description>
		<content:encoded><![CDATA[<p>Yes, addBoth is very handy. But one thing I&#8217;ve learned teaching (I also teach Python to new programmers): don&#8217;t try to introduce too many new things at once <img src='http://krondo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on An Introduction to Asynchronous Programming and Twisted by dave</title>
		<link>http://krondo.com/?p=2441&#038;cpage=1#comment-2941</link>
		<dc:creator>dave</dc:creator>
		<pubDate>Fri, 03 Sep 2010 01:49:01 +0000</pubDate>
		<guid isPermaLink="false">http://krondo.com/blog/?p=2441#comment-2941</guid>
		<description>Ah, you&#039;re trying to pretend that Twisted is really synchronous :) Yeah, that won&#039;t work, as you have discovered. You can&#039;t
mix sync and async code in the same Python process, at least not as easily as you are trying to do. Now you might be able
to run Twisted in a separate thread, I believe that has been done before. Then your main thread can still be synchronous.</description>
		<content:encoded><![CDATA[<p>Ah, you&#8217;re trying to pretend that Twisted is really synchronous <img src='http://krondo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Yeah, that won&#8217;t work, as you have discovered. You can&#8217;t<br />
mix sync and async code in the same Python process, at least not as easily as you are trying to do. Now you might be able<br />
to run Twisted in a separate thread, I believe that has been done before. Then your main thread can still be synchronous.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Twisted Introduction by dave</title>
		<link>http://krondo.com/?page_id=1327&#038;cpage=1#comment-2940</link>
		<dc:creator>dave</dc:creator>
		<pubDate>Fri, 03 Sep 2010 01:39:57 +0000</pubDate>
		<guid isPermaLink="false">http://dpeticol.webfactional.com/blog/?page_id=1327#comment-2940</guid>
		<description>Thank you, I appreciate the kind words! I am specifically aiming this tutorial for people who are new to Twisted and, more importantly, new to asynchronous programming. So your description is apt.</description>
		<content:encoded><![CDATA[<p>Thank you, I appreciate the kind words! I am specifically aiming this tutorial for people who are new to Twisted and, more importantly, new to asynchronous programming. So your description is apt.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Twisted Introduction by Laurens Van Houtven</title>
		<link>http://krondo.com/?page_id=1327&#038;cpage=1#comment-2937</link>
		<dc:creator>Laurens Van Houtven</dc:creator>
		<pubDate>Thu, 02 Sep 2010 22:45:59 +0000</pubDate>
		<guid isPermaLink="false">http://dpeticol.webfactional.com/blog/?page_id=1327#comment-2937</guid>
		<description>I think your tutorials are really awesome, and I love how you&#039;re consistently putting so much work into this while remaining responsive and approachable.

This was *long* overdue, but the official documentation page now links back to you:

http://twistedmatrix.com/trac/wiki/Documentation

I couldn&#039;t figure out if marketing your tutorials as good-for-newbies or not was doing you a disservice or not; I&#039;m just mainly using them as a pointer for newbies who are willing to learn. If you disagree with the wording, please feel free to e-mail me about it.</description>
		<content:encoded><![CDATA[<p>I think your tutorials are really awesome, and I love how you&#8217;re consistently putting so much work into this while remaining responsive and approachable.</p>
<p>This was *long* overdue, but the official documentation page now links back to you:</p>
<p><a href="http://twistedmatrix.com/trac/wiki/Documentation" rel="nofollow">http://twistedmatrix.com/trac/wiki/Documentation</a></p>
<p>I couldn&#8217;t figure out if marketing your tutorials as good-for-newbies or not was doing you a disservice or not; I&#8217;m just mainly using them as a pointer for newbies who are willing to learn. If you disagree with the wording, please feel free to e-mail me about it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on An Introduction to Asynchronous Programming and Twisted by Laurens Van Houtven</title>
		<link>http://krondo.com/?p=1682&#038;cpage=1#comment-2936</link>
		<dc:creator>Laurens Van Houtven</dc:creator>
		<pubDate>Thu, 02 Sep 2010 22:15:37 +0000</pubDate>
		<guid isPermaLink="false">http://krondo.com/blog/?p=1682#comment-2936</guid>
		<description>Yeah, I agree, the second one is definitely best. print, print is just too confusing for people reading 2.x code.

More minor nitpicking: there&#039;s a convenience method for blocks that conceptually match with &quot;finally&quot; clauses, much like this one:

d.addBoth(out)

Which, as the name suggests, adds the cb to both the cb and eb chains.

Thanks very much for your posts, again
lvh</description>
		<content:encoded><![CDATA[<p>Yeah, I agree, the second one is definitely best. print, print is just too confusing for people reading 2.x code.</p>
<p>More minor nitpicking: there&#8217;s a convenience method for blocks that conceptually match with &#8220;finally&#8221; clauses, much like this one:</p>
<p>d.addBoth(out)</p>
<p>Which, as the name suggests, adds the cb to both the cb and eb chains.</p>
<p>Thanks very much for your posts, again<br />
lvh</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on An Introduction to Asynchronous Programming and Twisted by Pet</title>
		<link>http://krondo.com/?p=2441&#038;cpage=1#comment-2932</link>
		<dc:creator>Pet</dc:creator>
		<pubDate>Thu, 02 Sep 2010 15:54:07 +0000</pubDate>
		<guid isPermaLink="false">http://krondo.com/blog/?p=2441#comment-2932</guid>
		<description>here is formated version of code http://codepad.org/WpvAZH80</description>
		<content:encoded><![CDATA[<p>here is formated version of code <a href="http://codepad.org/WpvAZH80" rel="nofollow">http://codepad.org/WpvAZH80</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on An Introduction to Asynchronous Programming and Twisted by Pet</title>
		<link>http://krondo.com/?p=2441&#038;cpage=1#comment-2931</link>
		<dc:creator>Pet</dc:creator>
		<pubDate>Thu, 02 Sep 2010 15:50:34 +0000</pubDate>
		<guid isPermaLink="false">http://krondo.com/blog/?p=2441#comment-2931</guid>
		<description>Yes, I know the way with deferredList. I think I&#039;d better explain with example code: there are 2 scripts, the first one is executed and use function from second script. script.py doesn&#039;t know that downloader function is asynchronious, that&#039;s my idea :)

script.py
from downloader import downloadPage
def main():
    
    print &#039;calling async function&#039;
    print &#039;which will return after its job has been done&#039;
    downloadPage(&#039;http://www.google.com&#039;, &#039;google.txt&#039;)
    print &#039;page has been downloaded&#039;
    print &#039;now i can do other stuff&#039;
    downloadPage(&#039;http://www.yahoo.com&#039;, &#039;yahoo.txt&#039;)
    print &#039;second page has been downloaded, not printed&#039;
    
main()



downloader.py
from twisted.web.client import getPage
from twisted.internet import defer

def _get(url):
    #from twisted.internet import reactor
    #I&#039;m using her reactor fo downloading a page with Agent.request()
    #and saving it to file, but for this example i&#039;m using getPage
    return getPage(url)

def downloadPage(url, filename):
    def done(_):
        from twisted.internet import reactor
        print &#039;stopping reactor&#039;
        reactor.stop()
        
    @defer.inlineCallbacks
    def _getPage(url, filename):
        page = &#039;&#039;
        try:
            page = yield _get(url)
        except Exception, e:
            print &quot;Exception: &quot;, e
        if page:
            print &#039;got page len&#039;, len(page)
            with open(filename, &#039;w&#039;) as f:
                f.write(page)            
            defer.returnValue(page)
        else:
            print &#039;no page sorry&#039;
            defer.returnValue(None)
        
    d = _getPage(url, filename)
    d.addBoth(done)
    
    from twisted.internet import reactor
    reactor.run()</description>
		<content:encoded><![CDATA[<p>Yes, I know the way with deferredList. I think I&#8217;d better explain with example code: there are 2 scripts, the first one is executed and use function from second script. script.py doesn&#8217;t know that downloader function is asynchronious, that&#8217;s my idea <img src='http://krondo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>script.py<br />
from downloader import downloadPage<br />
def main():</p>
<p>    print &#8216;calling async function&#8217;<br />
    print &#8216;which will return after its job has been done&#8217;<br />
    downloadPage(&#8216;http://www.google.com&#8217;, &#8216;google.txt&#8217;)<br />
    print &#8216;page has been downloaded&#8217;<br />
    print &#8216;now i can do other stuff&#8217;<br />
    downloadPage(&#8216;http://www.yahoo.com&#8217;, &#8216;yahoo.txt&#8217;)<br />
    print &#8216;second page has been downloaded, not printed&#8217;</p>
<p>main()</p>
<p>downloader.py<br />
from twisted.web.client import getPage<br />
from twisted.internet import defer</p>
<p>def _get(url):<br />
    #from twisted.internet import reactor<br />
    #I&#8217;m using her reactor fo downloading a page with Agent.request()<br />
    #and saving it to file, but for this example i&#8217;m using getPage<br />
    return getPage(url)</p>
<p>def downloadPage(url, filename):<br />
    def done(_):<br />
        from twisted.internet import reactor<br />
        print &#8216;stopping reactor&#8217;<br />
        reactor.stop()</p>
<p>    @defer.inlineCallbacks<br />
    def _getPage(url, filename):<br />
        page = &#8221;<br />
        try:<br />
            page = yield _get(url)<br />
        except Exception, e:<br />
            print &#8220;Exception: &#8220;, e<br />
        if page:<br />
            print &#8216;got page len&#8217;, len(page)<br />
            with open(filename, &#8216;w&#8217;) as f:<br />
                f.write(page)<br />
            defer.returnValue(page)<br />
        else:<br />
            print &#8216;no page sorry&#8217;<br />
            defer.returnValue(None)</p>
<p>    d = _getPage(url, filename)<br />
    d.addBoth(done)</p>
<p>    from twisted.internet import reactor<br />
    reactor.run()</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on An Introduction to Asynchronous Programming and Twisted by dave</title>
		<link>http://krondo.com/?p=2441&#038;cpage=1#comment-2929</link>
		<dc:creator>dave</dc:creator>
		<pubDate>Thu, 02 Sep 2010 14:53:59 +0000</pubDate>
		<guid isPermaLink="false">http://krondo.com/blog/?p=2441#comment-2929</guid>
		<description>You want something like this:
&lt;code&gt;
ds = []
for url in urls:
  ds.append(downloadPage(url))
dlist = DeferredList(ds)
dlist.addCallback(lambda r: reactor.stop())
&lt;/code&gt;
Make sense?</description>
		<content:encoded><![CDATA[<p>You want something like this:<br />
<code><br />
ds = []<br />
for url in urls:<br />
  ds.append(downloadPage(url))<br />
dlist = DeferredList(ds)<br />
dlist.addCallback(lambda r: reactor.stop())<br />
</code><br />
Make sense?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on An Introduction to Asynchronous Programming and Twisted by dave</title>
		<link>http://krondo.com/?p=2441&#038;cpage=1#comment-2928</link>
		<dc:creator>dave</dc:creator>
		<pubDate>Thu, 02 Sep 2010 14:52:01 +0000</pubDate>
		<guid isPermaLink="false">http://krondo.com/blog/?p=2441#comment-2928</guid>
		<description>Async will work fine for this, just don&#039;t have downloadPage(url) stop the reactor :)</description>
		<content:encoded><![CDATA[<p>Async will work fine for this, just don&#8217;t have downloadPage(url) stop the reactor <img src='http://krondo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on An Introduction to Asynchronous Programming and Twisted by Pet</title>
		<link>http://krondo.com/?p=2441&#038;cpage=1#comment-2921</link>
		<dc:creator>Pet</dc:creator>
		<pubDate>Thu, 02 Sep 2010 07:49:56 +0000</pubDate>
		<guid isPermaLink="false">http://krondo.com/blog/?p=2441#comment-2921</guid>
		<description>Hello Dave,

actually I&#039;ve wanted offer this function downloadPage(url) as utility, so client code could use it everywhere. With DeferredList I could pass a list of urls and download them, but limitation of calling the function only once remains or I should stop reactor in client code after all tasks are done. Looks like using synchronious function would much better in this case

Thanks for your help!</description>
		<content:encoded><![CDATA[<p>Hello Dave,</p>
<p>actually I&#8217;ve wanted offer this function downloadPage(url) as utility, so client code could use it everywhere. With DeferredList I could pass a list of urls and download them, but limitation of calling the function only once remains or I should stop reactor in client code after all tasks are done. Looks like using synchronious function would much better in this case</p>
<p>Thanks for your help!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
