<?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>Python Blog - All about python &#187; GIL</title>
	<atom:link href="http://www.python-blog.com/tag/gil/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.python-blog.com</link>
	<description>and technologies around</description>
	<lastBuildDate>Tue, 27 Jul 2010 19:58:17 +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>multiprocessing port scanner</title>
		<link>http://www.python-blog.com/2009/07/17/multiprocessing-port-scanner/</link>
		<comments>http://www.python-blog.com/2009/07/17/multiprocessing-port-scanner/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 14:55:04 +0000</pubDate>
		<dc:creator>Marcin Kuźmiński</dc:creator>
				<category><![CDATA[Multiprocessing]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[cores]]></category>
		<category><![CDATA[GIL]]></category>
		<category><![CDATA[global interpreter lock]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[pararell calculations]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[port scan]]></category>
		<category><![CDATA[port scanner]]></category>
		<category><![CDATA[python blog]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[Threads]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=125</guid>
		<description><![CDATA[I&#8217;d started to play with multiprocessing module that came up with python 2.6. Multiprocessing module is very similar to threading (it has almost the same functions/classes that threading).
Here are by my opinion three advantages over threading.

Multiprocessing runs on processes not threads.
Overcomes the GIL (global interpreter lock) that threading is using by using sub processes.
Processes can [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d started to play with multiprocessing module that came up with python 2.6. Multiprocessing module is very similar to threading (it has almost the same functions/classes that threading).</p>
<p>Here are by my opinion three advantages over threading.</p>
<ul>
<li>Multiprocessing runs on processes not threads.</li>
<li>Overcomes the GIL (global interpreter lock) that threading is using by using sub processes.</li>
<li>Processes can be synchronized even remotely so we could write a concurrent calculations over the network</li>
</ul>
<p>I made a simple example class that uses multiprocessing module to scan ports, just for testing i made the same thing that Lukasz made using threading. This example however is not more efficient than the one presented in <a href="http://www.python-blog.com/2009/07/01/python-threaded/" target="_blank">http://www.python-blog.com/2009/07/01/python-threaded/</a> but when we could replace the function check_port with more CPU consuming function we could end up with performance grater by the number of cpus/cores we have. For example in one of my projects recently i made a calculations for popular gambling game in Poland, MultiMulti. I&#8217;d made up a calculations of most repeating number in last 50 games. To calculate combination of 9&#8217;s over 20&#8217;s 50 times with threading i&#8217;d got around 1200s with multiprocessing i was able to calculate it in around 700 s with my Core2Duo CPU. I wish i had core2 quad to check the performance :) So i&#8217;f you need to make some heavy calculations multiprocessing can give you that performance.</p>
<p>Here&#8217;s the code and you can download the port descriptions file <a href="http://www.python-blog.com/wp-content/uploads/2009/07/port_list.data">port_list</a> to match port with description.</p>
<pre class="brush:python">from multiprocessing import Process, Queue, cpu_count, Lock
import socket, sys

class PortScanner(object):
    ''' multiprocessing port scanner with port description'''

    def __init__(self, host = '' , port_range = (1, 100), nr_processes = cpu_count(), port_list_file = ''):
        '''
        port_range=(start,stop) default 1,100
        nr_processes = int default cpu_count() '''
        q = Queue()
        l = Lock()
        port_list = []

        try:
            for i in open(port_list_file).readlines():
                port_list.append([x.strip() for x in i.split('\t')])

        except IOError:
            print 'no port list file specified'
            pass

        for _ in xrange(port_range[0], port_range[1]):
            q.put((host, _))

        #to stop all processes we have to put STOP to queue and break the loop for each process
        for _ in xrange(nr_processes):
            q.put('STOP')

        for _ in xrange(nr_processes):
            p = Process(target = self.check_port, args = (q, l, port_list))
            p.start()

    def check_port(self, q, l, port_list):
        ''' worker class invoked by process '''
        while True:
            queue_ret = q.get()

            if queue_ret == 'STOP':
                break

            s = socket.socket()

            try:

                s.connect((queue_ret))

                #lock for uncorrupted printing to console
                l.acquire()
                print "[INFO] %s on port %s is open" % (queue_ret)

                if len(port_list) &gt; 1:
                    for i in port_list:
                        if int(i[0]) == int(queue_ret[1]):
                            for _ in i:sys.stdout.write(_ + " ")
                            print "\n\n"

                l.release()
            except socket.error:
                #print "[WARNING] %s on port %s is closed" % (queue_ret)
                pass
            s.close()

if __name__ == "__main__":

    PortScanner(host = 'example.com', port_range = (1, 60), nr_processes = 40, port_list_file = 'port_list.data')</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2009/07/17/multiprocessing-port-scanner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python threads tutorial</title>
		<link>http://www.python-blog.com/2009/07/07/python-threads-tutorial/</link>
		<comments>http://www.python-blog.com/2009/07/07/python-threads-tutorial/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 08:29:59 +0000</pubDate>
		<dc:creator>Marcin Kuźmiński</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Threads]]></category>
		<category><![CDATA[GIL]]></category>
		<category><![CDATA[learning python]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[python blog]]></category>
		<category><![CDATA[thread queue]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=113</guid>
		<description><![CDATA[If you&#8217;re looking how to start with threads in python i found a great pdf to start with.
Download the Python-Threads pdf. Whitch includes the basic, and some more advanced information and tutorials about the threads in python.
In the pdf you can useful find info about:

thread and threading modules
queue
locks
gil
events
debugging threads

]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re looking how to start with threads in python i found a great pdf to start with.</p>
<p>Download the <strong><a href="http://www.python-blog.com/wp-content/uploads/2009/07/Python-Threads.pdf">Python-Threads</a></strong> pdf. Whitch includes the basic, and some more advanced information and tutorials about the threads in python.</p>
<p>In the pdf you can useful find info about:</p>
<ul>
<li>thread and threading modules</li>
<li>queue</li>
<li>locks</li>
<li>gil</li>
<li>events</li>
<li>debugging threads</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2009/07/07/python-threads-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyDev Python IDE &#8211; the best choice</title>
		<link>http://www.python-blog.com/2009/06/20/python-ide-pydev-best-choice/</link>
		<comments>http://www.python-blog.com/2009/06/20/python-ide-pydev-best-choice/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 14:33:34 +0000</pubDate>
		<dc:creator>Marcin Kuźmiński</dc:creator>
				<category><![CDATA[Editors]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[GIL]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[PyDev]]></category>
		<category><![CDATA[pydev extensions]]></category>
		<category><![CDATA[python blog]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=28</guid>
		<description><![CDATA[I went through many of python editors, and always came back to PyDev. Pydev in an plug-in to eclipse it comes with load of features, among them:

Package Explorer showing outline for python modules
Mylyn integration (separate feature: org.python.pydev.mylyn.feature)
Jython and Python support!
Support for scripting Pydev with Jython
Nice PYTHONPATH configuration!
Project and module creation wizards
Ctrl+Shift+O: Organizes imports or sorts [...]]]></description>
			<content:encoded><![CDATA[<p>I went through many of python editors, and always came back to <strong><a title="pydev" href="http://pydev.sourceforge.net" target="_blank">PyDev</a></strong>. Pydev in an plug-in to eclipse it comes with load of features, among them:</p>
<ul>
<li><strong>Package Explorer</strong> showing outline for python modules</li>
<li><strong><a href="http://www.eclipse.org/mylyn/">Mylyn</a></strong> integration (separate feature: org.python.pydev.mylyn.feature)</li>
<li>Jython and Python support!</li>
<li>Support for scripting Pydev with Jython</li>
<li>Nice PYTHONPATH configuration!</li>
<li>Project and module creation wizards</li>
<li>Ctrl+Shift+O: Organizes imports or sorts selection alphabetically</li>
<li>Ctrl+Shift+F: Autoformat your code (preferences can be set)</li>
<li>Python 2.4, 2.5, 2.6, 3.0 syntax supported</li>
<li>Pydev builders can be disabled</li>
<li>Syntax highlighting</li>
<li>Spell checking (depends on JDT for Eclipse 3.3)</li>
<li>Hovering in errors shows descriptions</li>
<li>Matching brackets highlighted.</li>
<li>Parser errors marked in the task list</li>
<li>Outline view with imports/functions/classes</li>
<li>Tabs or spaces preference</li>
<li>Smart indentation (indent and dedent)</li>
<li>Navigation: keyboard shortcuts to previous or next function. <em>Default: (Ctrl+Shift+Up and Ctrl+Shift+Down) </em></li>
<li>Comment and uncomment commands (on the popup menu) and keybindings. <em>Default: (Ctrl+3 and Ctrl+Shift+3) </em></li>
<li>hyperlinks over functions//import statements</li>
<li>Code folding</li>
<li><a href="http://pydev.sourceforge.net/refactoring.html">Refactoring</a> with <a href="http://bicyclerepair.sourceforge.net/">bicycle repair man</a>.</li>
<li><a href="http://pydev.sourceforge.net/codecompletion.html">Code Completion</a> <em>(Ctrl+Space) </em></li>
<li>Templates Completion <em>(Ctrl+Space Too) </em></li>
<li>Go to definition with <em>F3</em> (powered by <a href="http://bicyclerepair.sourceforge.net/">bicycle repair man</a>)</li>
<li><a href="http://pydev.sourceforge.net/contentassist.html">Content Assistant</a> <em>(Ctrl+1)</em></li>
<li><a href="http://pydev.sourceforge.net/codecoverage.html">Code Coverage</a></li>
<li><a href="http://pydev.sourceforge.net/pylint.html">Pylint </a></li>
<li><a href="http://pydev.sourceforge.net/tasks.html">TODO tasks</a></li>
<li>Background and current line color chooser.</li>
</ul>
<p>I highly recommend using <strong><a href="http://pydev.sourceforge.net/pylint.html">Pylint </a></strong>in pydev it really helps to keep the code good quality. <a href="http://pydev.sourceforge.net/pylint.html">Pylint </a> analyzes your code and shows unnecessary variables and imports, provides helpers to clean up the code and many more.</p>
<p>To install pydev just add <strong><span style="text-decoration: line-through;">http://pydev.sourceforge.net/updates/</span> </strong><strong><a href="http://pydev.org/updates">http://pydev.org/updates</a></strong><strong> (see update below)</strong> link to eclipse by using software updates and addons option.<br />
I&#8217;m using the nightly builds for eclipse (http://nightly.aptana.com/pydev/) because they always come with new features earlier than the main release but remember use it on your own responsibility. You can find how to setup pydev <strong><a title="pydev installation instructions" href="http://www.fabioz.com/pydev/manual_101_root.html" target="_blank">here</a></strong>. When your up and running with pydev download pylint from <a title="pylint download page" href="http://www.logilab.org/project/pylint" target="_blank"><strong>here</strong></a> don&#8217;t forget the necessary dependencies i.e: logilab-astng, logilab-common, links are on the pylint download site. The turn on pylint you have to add a path to lint.py file in pylint tab on pydev options in eclipse. After restart of eclipse you should see output from pylint on the eclipse console anytime when you save a python file.</p>
<p>Now enjoy the <strong>most powerful python IDE available</strong> :-)</p>
<p>UPDATE: since PyDev release 1.5 now the package have integrated a pyDev extensions&#8230; the new repository for eclipse containing the version 1.5 is :<strong><a href="http://pydev.org/updates">http://pydev.org/updates</a></strong><br />
I also added a post about the PyDev extensions see it here <strong>http://www.python-blog.com/2009/09/06/pydev-extension-now-open-source/</strong><a href="http://www.python-blog.com/2009/09/06/pydev-extension-now-open-source/"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2009/06/20/python-ide-pydev-best-choice/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
