<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>udayv . soundc &#187; python</title>
	<atom:link href="http://www.soundc.de/blog/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.soundc.de/blog</link>
	<description>Electronic Music, Programming</description>
	<lastBuildDate>Tue, 04 May 2010 14:36:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Why Python is so awesome sometimes</title>
		<link>http://www.soundc.de/blog/2010/02/02/why-python-is-so-awesome-sometimes/</link>
		<comments>http://www.soundc.de/blog/2010/02/02/why-python-is-so-awesome-sometimes/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 22:31:26 +0000</pubDate>
		<dc:creator>verma</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[awesome]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.soundc.de/blog/?p=201</guid>
		<description><![CDATA[Here&#8217;s why I totally love python sometimes:

def _callService (self, headers, callback, errback = None, method='GET'):
    # ....
    return some_val

def _callServiceGET (*args, **kwargs):
    return args[0]._callService (*args[1:], method='GET', **kwargs)

def _callServiceHEAD (*args, **kwargs):
    return args[0]._callService (*args[1:], method='HEAD', **kwargs)

/
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s why I totally love python sometimes:</p>
<pre class="brush: python;">
def _callService (self, headers, callback, errback = None, method='GET'):
    # ....
    return some_val

def _callServiceGET (*args, **kwargs):
    return args[0]._callService (*args[1:], method='GET', **kwargs)

def _callServiceHEAD (*args, **kwargs):
    return args[0]._callService (*args[1:], method='HEAD', **kwargs)
</pre>
<p>/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.soundc.de/blog/2010/02/02/why-python-is-so-awesome-sometimes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interprocess Synchronization in Python/Linux</title>
		<link>http://www.soundc.de/blog/2008/10/21/interprocess-synchronization-in-pythonlinux/</link>
		<comments>http://www.soundc.de/blog/2008/10/21/interprocess-synchronization-in-pythonlinux/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 00:48:15 +0000</pubDate>
		<dc:creator>verma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[interprocess]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[syncrhonization]]></category>

		<guid isPermaLink="false">http://www.soundc.de/blog/?p=103</guid>
		<description><![CDATA[I had been looking for a way to synchronize my python cgi scripts (several, or several instances of one) so that only one of them could access a particular table in a database at one time.  I looked around on the internet but didn&#8217;t find a concrete class that could do this.  I was writing [...]]]></description>
			<content:encoded><![CDATA[<p>I had been looking for a way to synchronize my python cgi scripts (several, or several instances of one) so that only one of them could access a particular table in a database at one time.  I looked around on the internet but didn&#8217;t find a concrete class that could do this.  I was writing my scripts for a linux based apache server, so portability didn&#8217;t matter.  So here it is.</p>
<pre class="brush: python;">
#!/usr/bin/python
#
import os
import fcntl

class lock:
        def __init__(self):
                self.lockf = 0
                self.file = 0

        def lock(self):
                self.lockf = open ('/tmp/mytmpfilename.1001', 'a')
                fcntl.flock (self.lockf, fcntl.LOCK_EX)
                self.file = open ('/tmp/mytmpfilename.1001','w')

        def unlock(self):
                self.file.close ()
                self.lockf.close ()

###
</pre>
<p>If you know of a better way of synchronizing processes, please let me know.</p>
<p>Edit.10/21/2008:</p>
<p>Here is more specifically what my scripts do.  Perhaps, this post makes more sense in the correct context.  The description below was taken from one of my comments.</p>
<p>All instances of my cgi script perform a read operation followed by a delete operation.  Essentially, my script reads the top row from the database. Right after the information is retrieved that particular row is deleted.  In other words, I am using my database as a FIFO buffer.  Now if several instances of my scripts are running, more than one of them could access the first row (read it), thereby letting two different processes fetch the same element from a FIFO.  One but all of them then fails with the deletion operation.  The whole idea behind this locking mechanism was to avoid this.  All instances of my script should always fetch a different item.</p>
<p>/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.soundc.de/blog/2008/10/21/interprocess-synchronization-in-pythonlinux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

