<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Python on </title>
    <link>https://bzimmer.ziclix.com/tags/python/</link>
    <description>Recent content in Python on </description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sun, 21 Dec 2025 19:32:21 +0100</lastBuildDate>
    <atom:link href="https://bzimmer.ziclix.com/tags/python/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Python thread dumps.</title>
      <link>https://bzimmer.ziclix.com/2008/12/17/python-thread-dumps/</link>
      <pubDate>Wed, 17 Dec 2008 00:00:00 +0000</pubDate>
      <guid>https://bzimmer.ziclix.com/2008/12/17/python-thread-dumps/</guid>
      <description>&lt;p&gt;For some time I&amp;rsquo;ve wanted the equivalent of Java&amp;rsquo;s ability to dump the stack trace of all currently running threads in Python as a means for debugging some hung processes. I finally found a solution and wired it up to the services&amp;rsquo; http console:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; sys&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; traceback&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; pygments &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; highlight&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; pygments.lexers &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; PythonLexer&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; pygments.formatters &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; HtmlFormatter&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;stacktraces&lt;/span&gt;():&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    code &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; threadId, stack &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; sys&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_current_frames()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;items():&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        code&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\n&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;# ThreadID: &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;%s&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;%&lt;/span&gt; threadId)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; filename, lineno, name, line &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; traceback&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extract_stack(stack):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            code&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;File: &amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;%s&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;, line &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;%d&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;, in &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;%s&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;%&lt;/span&gt; (filename, lineno, name))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; line:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                code&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;  &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;%s&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;%&lt;/span&gt; (line&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;strip()))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; highlight(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\n&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;join(code), PythonLexer(), HtmlFormatter(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      full&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;False&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#75715e&#34;&gt;# style=&amp;#34;native&amp;#34;,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      noclasses&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;True&lt;/span&gt;))&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;The magic happens with &lt;code&gt;sys._current_frames()&lt;/code&gt; which returns exactly what I wanted. The only outstanding issue is how to get the thread&amp;rsquo;s name to display in addition to the ident.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Albums, predicates, SmugMug, pysmug v0.5.</title>
      <link>https://bzimmer.ziclix.com/2008/10/14/albums-predicates-smugmug-pysmug-v05/</link>
      <pubDate>Tue, 14 Oct 2008 00:00:00 +0000</pubDate>
      <guid>https://bzimmer.ziclix.com/2008/10/14/albums-predicates-smugmug-pysmug-v05/</guid>
      <description>&lt;p&gt;I have a lot of &lt;a href=&#34;http://smugmug.com/&#34;&gt;SmugMug&lt;/a&gt; albums and sometimes I have a hard time tracking down in which Category and SubCategory one resides or whether I&amp;rsquo;ve updated all the albums to use square thumbnails &amp;ndash; thus was born smugfind.&lt;/p&gt;&#xA;&lt;p&gt;I just released version 0.5 of &lt;a href=&#34;http://code.google.com/p/pysmug/&#34;&gt;pysmug&lt;/a&gt; which includes smugfind and some minor bug fixes. It&amp;rsquo;s available &lt;a href=&#34;http://code.google.com/p/pysmug/downloads/list&#34;&gt;here&lt;/a&gt; for download or through hg (courtesy freehg):&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;$ hg clone -r v0.5 &lt;a href=&#34;http://freehg.org/u/bzimmer/pysmug/&#34;&gt;http://freehg.org/u/bzimmer/pysmug/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;To show help:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ smugfind -h&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Usage: smugfind &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt;options&lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Options:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  -h, --help            show this help message and exit&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  -s, --sharegroups     display sharegroup&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  -f FIELDS, --fields&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;FIELDS&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        list of fields to display &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; each entity&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  -l, --list            available list of fields to display&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  -p PREDICATE, --predicate&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;PREDICATE&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        predicate to evaluate&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;To see all the possible metadata fields:&lt;/p&gt;</description>
    </item>
    <item>
      <title>pysmug, tag clouds, asynch IO and the SmugMug API.</title>
      <link>https://bzimmer.ziclix.com/2008/06/12/pysmug-tag-clouds-asynch-io-and-the-smugmug-api/</link>
      <pubDate>Thu, 12 Jun 2008 00:00:00 +0000</pubDate>
      <guid>https://bzimmer.ziclix.com/2008/06/12/pysmug-tag-clouds-asynch-io-and-the-smugmug-api/</guid>
      <description>&lt;p&gt;A question was asked on a dgrin &lt;a href=&#34;http://www.dgrin.com/showthread.php?t=95977&#34;&gt;thread&lt;/a&gt; about whether the &lt;a href=&#34;http://www.smugmug.com/&#34;&gt;SmugMug&lt;/a&gt; API supported building a tag cloud &amp;ndash; it doesn&amp;rsquo;t. A responder suggested it would take far too long to generate one from the API since you&amp;rsquo;d have to trawl through every photo. This is indeed true, but you don&amp;rsquo;t have to do it serially. I consider the &lt;a href=&#34;http://code.google.com/p/pysmug/wiki/Batchables&#34;&gt;batchable&lt;/a&gt; interface for &lt;a href=&#34;http://code.google.com/p/pysmug/&#34;&gt;pysmug&lt;/a&gt; to be it&amp;rsquo;s selling point and building a tag cloud is the perfect demonstration.&lt;/p&gt;</description>
    </item>
    <item>
      <title>pysmug on Python2.6a3.</title>
      <link>https://bzimmer.ziclix.com/2008/05/16/pysmug-on-python26a3/</link>
      <pubDate>Fri, 16 May 2008 00:00:00 +0000</pubDate>
      <guid>https://bzimmer.ziclix.com/2008/05/16/pysmug-on-python26a3/</guid>
      <description>&lt;p&gt;I decided tonight was the night to try &lt;a href=&#34;http://www.python.org/download/releases/2.6/&#34;&gt;Python2.6a3&lt;/a&gt; on my macbook pro with a goal of getting &lt;a href=&#34;http://code.google.com/p/pysmug/&#34;&gt;pysmug&lt;/a&gt; to run on it.&lt;/p&gt;&#xA;&lt;p&gt;After downloading and doing the typical &lt;code&gt;configure &amp;amp;amp;&amp;amp;amp; make&lt;/code&gt; dance I saw this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Failed to find the necessary bits to build these modules:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;bsddb185          gdbm              linuxaudiodev&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ossaudiodev       readline          spwd&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sunaudiodev&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;Apparently &lt;code&gt;setup.py&lt;/code&gt; won&amp;rsquo;t build the &lt;code&gt;readline&lt;/code&gt; module with the stock readline library on my mac. I already installed libreadline from &lt;a href=&#34;http://www.macports.org/&#34;&gt;MacPorts&lt;/a&gt; so I applied the following patch:&lt;/p&gt;</description>
    </item>
    <item>
      <title>pysmug 0.4 released.</title>
      <link>https://bzimmer.ziclix.com/2008/05/14/pysmug-04-released/</link>
      <pubDate>Wed, 14 May 2008 00:00:00 +0000</pubDate>
      <guid>https://bzimmer.ziclix.com/2008/05/14/pysmug-04-released/</guid>
      <description>&lt;p&gt;I just released version 0.4 of &lt;a href=&#34;http://code.google.com/p/pysmug/&#34;&gt;pysmug&lt;/a&gt; and I&amp;rsquo;m pretty happy with the additional functionality.&lt;/p&gt;&#xA;&lt;p&gt;The most significant additions to the ChangeLog referenced in my &lt;a href=&#34;https://bzimmer.ziclix.com/2008/05/11/pysmug-version-04-coming-soon/&#34;&gt;previous post&lt;/a&gt; are the migration of examples to tests and the overhauled configuration file format for &lt;code&gt;pysmug.login()&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;tests&#34;&gt;tests&lt;/h3&gt;&#xA;&lt;p&gt;I&amp;rsquo;m generally a proponent of testing but since so much of pysmug is dependent on SmugMug services I added examples rather than tests. That&amp;rsquo;s changed with v0.4 &amp;ndash; the examples have either been converted to code in &lt;code&gt;SmugTool&lt;/code&gt; and/or migrated to a test case. I took the opportunity to learn &lt;a href=&#34;http://www.somethingaboutorange.com/mrl/projects/nose/&#34;&gt;nose&lt;/a&gt; and I&amp;rsquo;m not upset with the decision. When I switched from in-function preparing of SmugMug-style parameters names to using a decorator it was nice to have the tests to back me up.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Python decorators.</title>
      <link>https://bzimmer.ziclix.com/2008/05/14/python-decorators/</link>
      <pubDate>Wed, 14 May 2008 00:00:00 +0000</pubDate>
      <guid>https://bzimmer.ziclix.com/2008/05/14/python-decorators/</guid>
      <description>&lt;p&gt;I finally found a non-trivial reason to implement a Python &lt;a href=&#34;http://www.python.org/dev/peps/pep-0318/&#34;&gt;decorator&lt;/a&gt;. I make extensive use of Python keyword arguments in the &lt;a href=&#34;http://code.google.com/p/pysmug/&#34;&gt;&lt;code&gt;pysmug&lt;/code&gt;&lt;/a&gt; API and map those spellings to SmugMug keyword arguments. The algorithm for converting a Python spelling to a SmugMug spelling is pretty straight forward and easily wrapped up in a function. Originally, the first line of every function required formatting the keywords into SmugMug-style spellings by calling &lt;code&gt;self._prepare_keywords(**kwargs)&lt;/code&gt;. It occurred to me this is a perfect use case for decorators so I converted the code from a class method to a function, moved the call up a line, prefixed a &lt;code&gt;@&lt;/code&gt; and voilà, a far more explicit communication about how this method handles keyword arguments &amp;ndash; love it.&lt;/p&gt;</description>
    </item>
    <item>
      <title>pysmug version 0.4 coming soon</title>
      <link>https://bzimmer.ziclix.com/2008/05/11/pysmug-version-04-coming-soon/</link>
      <pubDate>Sun, 11 May 2008 00:00:00 +0000</pubDate>
      <guid>https://bzimmer.ziclix.com/2008/05/11/pysmug-version-04-coming-soon/</guid>
      <description>&lt;p&gt;While I hammer away at &lt;a href=&#34;http://code.google.com/p/erlsmug/&#34;&gt;erlsmug&lt;/a&gt; and try to figure out why it&amp;rsquo;s so much slower than &lt;a href=&#34;http://code.google.com/p/pysmug/&#34;&gt;pysmug&lt;/a&gt; and &lt;a href=&#34;http://pycurl.sourceforge.net/&#34;&gt;PycURL&lt;/a&gt;, I&amp;rsquo;m ready to release version 0.4 of pysmug.&lt;/p&gt;&#xA;&lt;p&gt;Among the biggest changes are compatibility with new &lt;a href=&#34;http://blogs.smugmug.com/don/2008/02/08/big-privacy-changes-at-smugmug/&#34;&gt;security changes&lt;/a&gt; required for version 1.2.2 of the SmugMug API. It&amp;rsquo;s now also possible to register function callbacks for PycURL&amp;rsquo;s verbose and progress handlers.&lt;/p&gt;&#xA;&lt;p&gt;In testing erlsmug&amp;rsquo;s concurrency, I wrote a function to return all the details of an album as well as the details about each image, including EXIF. This requires 1 call to get the album info, 1 call to get the images for an album and one call each for simple and EXIF details per image. This function, &lt;code&gt;albums_details&lt;/code&gt; was so useful I wanted it for pysmug.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
