<?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 searching for signal</title>
	<atom:link href="http://blog.n01se.net/?feed=comments-rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.n01se.net</link>
	<description>theoretically unambiguous</description>
	<lastBuildDate>Sun, 29 Aug 2010 20:06:38 +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 Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by How to capture httplib2 debug in a threaded app &#171; searching for signal</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2475</link>
		<dc:creator>How to capture httplib2 debug in a threaded app &#171; searching for signal</dc:creator>
		<pubDate>Sun, 29 Aug 2010 20:06:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2475</guid>
		<description>[...] searching for signal theoretically unambiguous      &#171; Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] searching for signal theoretically unambiguous      &laquo; Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by Cowmix</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2370</link>
		<dc:creator>Cowmix</dc:creator>
		<pubDate>Sun, 11 Jul 2010 04:06:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2370</guid>
		<description>Pycurl is not a great option because it depends on the native curl lib.</description>
		<content:encoded><![CDATA[<p>Pycurl is not a great option because it depends on the native curl lib.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by agriffis</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2322</link>
		<dc:creator>agriffis</dc:creator>
		<pubDate>Mon, 05 Jul 2010 02:00:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2322</guid>
		<description>@Hans: Thanks for the suggestion to submit a bug report. I will pursue that.

@Jason: pycurl looks interesting, thanks. I may use it for a later project. I regularly use command-line curl for testing and debugging.

@Adam: Thanks for the pointer! But take a look at the commit message, &quot;Restore suport for set_debuglevel&quot; (sic). The original debuglevel and print statements go back to 1994 at least...

@Tom: I&#039;ll definitely look at lazr.restfulclient, thanks.

@Ben: Our server portion is running under mod_wsgi with a mix of processes and threads. In any case, I don&#039;t think I&#039;d want to disallow threads in my application to solve this particular problem, though there may be lots of other good reasons to consider processes in favor over threads. Regarding Ruby, thanks for the suggestion. I&#039;ll leave it at that. :-)

@Stu: The point of the blog post was to ask for help and to express dismay at the current implementation. I will also pursue filing a bug, but for the sake of a fixing a future release, which is a different goal.

@Andrew: THANK YOU! I knew that I could replace sys.stdout to redirect print, but I didn&#039;t consider that duck typing might actually work in this context. I looked at Alex&#039;s implementation and also a 1994 email from Guido (see http://n01se.net/paste/sM72 ) and I now have a working implementation:

&lt;pre class=&quot;brush:python;gutter:false&quot;&gt;
class LocalCapturingWriter(threading.local):
    def __init__(self, fp):
        self._fp = fp
        self._stringio = None

    def start_capture(self):
        self._stringio = cStringIO.StringIO()

    def stop_capture(self):
        v = self._stringio.getvalue()
        self._stringio.close()
        self._stringio = None
        return v

    def write(self, str):
        if self._stringio:
            return self._stringio.write(str)
        else:
            return self._fp.write(str)

sys.stdout = LocalCapturingWriter(sys.stdout)
&lt;/pre&gt;

I&#039;m not sure yet if this minimalistic approach will be sufficient or if I&#039;ll need to implement __setattr__ and maybe some other special methods. My testing suggests it&#039;s enough. Immediately before calling Http.request() I call sys.stdout.start_capture(), then I call sys.stdout.stop_capture() afterward to fetch the trace and restore sys.stdout for this thread.

When I&#039;ve had a chance to test this more thoroughly, especially in the context of our app rather than just a test program, I&#039;ll update the post to include this info. Thanks again!</description>
		<content:encoded><![CDATA[<p>@Hans: Thanks for the suggestion to submit a bug report. I will pursue that.</p>
<p>@Jason: pycurl looks interesting, thanks. I may use it for a later project. I regularly use command-line curl for testing and debugging.</p>
<p>@Adam: Thanks for the pointer! But take a look at the commit message, &#8220;Restore suport for set_debuglevel&#8221; (sic). The original debuglevel and print statements go back to 1994 at least&#8230;</p>
<p>@Tom: I&#8217;ll definitely look at lazr.restfulclient, thanks.</p>
<p>@Ben: Our server portion is running under mod_wsgi with a mix of processes and threads. In any case, I don&#8217;t think I&#8217;d want to disallow threads in my application to solve this particular problem, though there may be lots of other good reasons to consider processes in favor over threads. Regarding Ruby, thanks for the suggestion. I&#8217;ll leave it at that. <img src='http://blog.n01se.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>@Stu: The point of the blog post was to ask for help and to express dismay at the current implementation. I will also pursue filing a bug, but for the sake of a fixing a future release, which is a different goal.</p>
<p>@Andrew: THANK YOU! I knew that I could replace sys.stdout to redirect print, but I didn&#8217;t consider that duck typing might actually work in this context. I looked at Alex&#8217;s implementation and also a 1994 email from Guido (see <a href="http://n01se.net/paste/sM72" rel="nofollow">http://n01se.net/paste/sM72</a> ) and I now have a working implementation:</p>
<pre class="brush:python;gutter:false">
class LocalCapturingWriter(threading.local):
    def __init__(self, fp):
        self._fp = fp
        self._stringio = None

    def start_capture(self):
        self._stringio = cStringIO.StringIO()

    def stop_capture(self):
        v = self._stringio.getvalue()
        self._stringio.close()
        self._stringio = None
        return v

    def write(self, str):
        if self._stringio:
            return self._stringio.write(str)
        else:
            return self._fp.write(str)

sys.stdout = LocalCapturingWriter(sys.stdout)
</pre>
<p>I&#8217;m not sure yet if this minimalistic approach will be sufficient or if I&#8217;ll need to implement __setattr__ and maybe some other special methods. My testing suggests it&#8217;s enough. Immediately before calling Http.request() I call sys.stdout.start_capture(), then I call sys.stdout.stop_capture() afterward to fetch the trace and restore sys.stdout for this thread.</p>
<p>When I&#8217;ve had a chance to test this more thoroughly, especially in the context of our app rather than just a test program, I&#8217;ll update the post to include this info. Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by Stu</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2320</link>
		<dc:creator>Stu</dc:creator>
		<pubDate>Mon, 05 Jul 2010 00:06:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2320</guid>
		<description>Please submit a bug for this, it should take less time than writing this blog post did, and it may even get fixed.

(Or even submit some patches too)</description>
		<content:encoded><![CDATA[<p>Please submit a bug for this, it should take less time than writing this blog post did, and it may even get fixed.</p>
<p>(Or even submit some patches too)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by Andrew Dalke</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2315</link>
		<dc:creator>Andrew Dalke</dc:creator>
		<pubDate>Sun, 04 Jul 2010 22:45:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2315</guid>
		<description>Not speaking about the quality of the library, but to your problem. You can replace sys.stdout with something which serializes requests for you. A quick search found one such proposal by Alex Martelli at http://stackoverflow.com/questions/3029816/how-do-i-get-a-thread-safe-print-in-python-2-6 .

That solution might be more complete than you need, since it handles the &quot;softspace&quot; special attribute in file handles. That will only come up in httplib.py when the line &#039;print &quot;header:&quot;, hdr,&#039; (because of the trailing &quot;,&quot;), but in this case I think that&#039;s a newline so it&#039;s not that important and you can fake a solution in other ways.

You can also get the thread id and prefix every output line with it, in order to help reassemble the debug statements.</description>
		<content:encoded><![CDATA[<p>Not speaking about the quality of the library, but to your problem. You can replace sys.stdout with something which serializes requests for you. A quick search found one such proposal by Alex Martelli at <a href="http://stackoverflow.com/questions/3029816/how-do-i-get-a-thread-safe-print-in-python-2-6" rel="nofollow">http://stackoverflow.com/questions/3029816/how-do-i-get-a-thread-safe-print-in-python-2-6</a> .</p>
<p>That solution might be more complete than you need, since it handles the &#8220;softspace&#8221; special attribute in file handles. That will only come up in httplib.py when the line &#8216;print &#8220;header:&#8221;, hdr,&#8217; (because of the trailing &#8220;,&#8221;), but in this case I think that&#8217;s a newline so it&#8217;s not that important and you can fake a solution in other ways.</p>
<p>You can also get the thread id and prefix every output line with it, in order to help reassemble the debug statements.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by Benjami Sergeant</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2313</link>
		<dc:creator>Benjami Sergeant</dc:creator>
		<pubDate>Sun, 04 Jul 2010 22:39:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2313</guid>
		<description>Or for that matter, what if you use Ruby instead of Python?</description>
		<content:encoded><![CDATA[<p>Or for that matter, what if you use Ruby instead of Python?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by Benjamin Sergeant</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2312</link>
		<dc:creator>Benjamin Sergeant</dc:creator>
		<pubDate>Sun, 04 Jul 2010 21:48:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2312</guid>
		<description>What if you use multiprocessing instead of threads ?

http://docs.python.org/library/multiprocessing.html</description>
		<content:encoded><![CDATA[<p>What if you use multiprocessing instead of threads ?</p>
<p><a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow">http://docs.python.org/library/multiprocessing.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by Tom Berger</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2309</link>
		<dc:creator>Tom Berger</dc:creator>
		<pubDate>Sun, 04 Jul 2010 20:59:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2309</guid>
		<description>If you need to implement RESTful services and clients in Python, check out https://launchpad.net/lazr.restful and https://launchpad.net/lazr.restfulclient

These packages are quite polished, they were written for implementing Launchpad&#039;s restful services but are designed as a general purpose just-add-water package for exposing Python objects as RESTful services and creating a pythonic client library.</description>
		<content:encoded><![CDATA[<p>If you need to implement RESTful services and clients in Python, check out <a href="https://launchpad.net/lazr.restful" rel="nofollow">https://launchpad.net/lazr.restful</a> and <a href="https://launchpad.net/lazr.restfulclient" rel="nofollow">https://launchpad.net/lazr.restfulclient</a></p>
<p>These packages are quite polished, they were written for implementing Launchpad&#8217;s restful services but are designed as a general purpose just-add-water package for exposing Python objects as RESTful services and creating a pythonic client library.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by Adam Collard</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2307</link>
		<dc:creator>Adam Collard</dc:creator>
		<pubDate>Sun, 04 Jul 2010 20:38:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2307</guid>
		<description>Looks like this first came in around the latter end of 2000: http://svn.python.org/view/python/trunk/Lib/httplib.py?r1=17415&amp;r2=17527</description>
		<content:encoded><![CDATA[<p>Looks like this first came in around the latter end of 2000: <a href="http://svn.python.org/view/python/trunk/Lib/httplib.py?r1=17415&amp;r2=17527" rel="nofollow">http://svn.python.org/view/python/trunk/Lib/httplib.py?r1=17415&amp;r2=17527</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Python&#8217;s httplib uses print for debugging. Oh, it hurts&#8230; by Jason Baker</title>
		<link>http://blog.n01se.net/?p=213&#038;cpage=1#comment-2306</link>
		<dc:creator>Jason Baker</dc:creator>
		<pubDate>Sun, 04 Jul 2010 20:29:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.n01se.net/?p=213#comment-2306</guid>
		<description>It should be noted that httplib and urllib are considered by many to be some of the worst parts of the standard library.  I haven&#039;t used it myself, but I&#039;ve heard good things about pycurl:  http://pycurl.sourceforge.net/</description>
		<content:encoded><![CDATA[<p>It should be noted that httplib and urllib are considered by many to be some of the worst parts of the standard library.  I haven&#8217;t used it myself, but I&#8217;ve heard good things about pycurl:  <a href="http://pycurl.sourceforge.net/" rel="nofollow">http://pycurl.sourceforge.net/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.259 seconds -->
