<?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 Artful Code</title>
	<atom:link href="http://www.artfulcode.net/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artfulcode.net</link>
	<description>Resources and tips for dynamic, interactive languages.</description>
	<lastBuildDate>Mon, 23 Jan 2012 14:26:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comment on Multi-threading in Python by Alfe</title>
		<link>http://www.artfulcode.net/articles/multi-threading-python/comment-page-1/#comment-3768</link>
		<dc:creator>Alfe</dc:creator>
		<pubDate>Mon, 23 Jan 2012 14:26:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/multi-threading-python/#comment-3768</guid>
		<description>Hmpf.  Sorry for spamming :-(

The blog does not allow removing old posts and does not handle hard spaces properly at all places.  I hope you can decipher my code nevertheless.

Alfe</description>
		<content:encoded><![CDATA[<p>Hmpf.  Sorry for spamming :-(</p>
<p>The blog does not allow removing old posts and does not handle hard spaces properly at all places.  I hope you can decipher my code nevertheless.</p>
<p>Alfe</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multi-threading in Python by Alfe</title>
		<link>http://www.artfulcode.net/articles/multi-threading-python/comment-page-1/#comment-3767</link>
		<dc:creator>Alfe</dc:creator>
		<pubDate>Mon, 23 Jan 2012 14:24:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/multi-threading-python/#comment-3767</guid>
		<description>I agree with Alastair.

class Worker(threading.Thread):
    def __init__(self, taskQueue, resultQueue):
        self.taskQueue = taskQueue
        self.resultQueue = resultQueue
        super(threading.Thread, self).__init__()
    def run(self):
        while True:  # until end marker found
            try:
                url = self.taskQueue().get(True)
                if url is None:  # end-marker?
                    self.resultQueue.put(self)  # report being finished
                f = urllib.urlopen(url)
                contents = f.read()
                f.close()
                self.resultQueue.put(contents)
            except Exception, e:
                self.resultQueue.put(e)

def get_files(urls):
    taskQueue = Queue()
    for url in urls:
        taskQueue.put(url)
    resultQueue = Queue()
    workers = set([ Worker(taskQueue, resultQueue) for i in range(4) ])
    for worker in workers:
        worker.start()
        taskQueue.put(None)  # one end marker for each worker thread
    while workers:
        result = resultQueue.get(True)
        if result in workers:
            workers.remove(result)
        else:
            yield result</description>
		<content:encoded><![CDATA[<p>I agree with Alastair.</p>
<p>class Worker(threading.Thread):<br />
    def __init__(self, taskQueue, resultQueue):<br />
        self.taskQueue = taskQueue<br />
        self.resultQueue = resultQueue<br />
        super(threading.Thread, self).__init__()<br />
    def run(self):<br />
        while True:  # until end marker found<br />
            try:<br />
                url = self.taskQueue().get(True)<br />
                if url is None:  # end-marker?<br />
                    self.resultQueue.put(self)  # report being finished<br />
                f = urllib.urlopen(url)<br />
                contents = f.read()<br />
                f.close()<br />
                self.resultQueue.put(contents)<br />
            except Exception, e:<br />
                self.resultQueue.put(e)</p>
<p>def get_files(urls):<br />
    taskQueue = Queue()<br />
    for url in urls:<br />
        taskQueue.put(url)<br />
    resultQueue = Queue()<br />
    workers = set([ Worker(taskQueue, resultQueue) for i in range(4) ])<br />
    for worker in workers:<br />
        worker.start()<br />
        taskQueue.put(None)  # one end marker for each worker thread<br />
    while workers:<br />
        result = resultQueue.get(True)<br />
        if result in workers:<br />
            workers.remove(result)<br />
        else:<br />
            yield result</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multi-threading in Python by Alfe</title>
		<link>http://www.artfulcode.net/articles/multi-threading-python/comment-page-1/#comment-3766</link>
		<dc:creator>Alfe</dc:creator>
		<pubDate>Mon, 23 Jan 2012 14:21:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/multi-threading-python/#comment-3766</guid>
		<description>I agree with Alastair.

class Worker(threading.Thread):
    def __init__(self, taskQueue, resultQueue):
        self.taskQueue = taskQueue
        self.resultQueue = resultQueue
        super(threading.Thread, self).__init__()
    def run(self):
        while True:  # until end marker found
            try:
                url = self.taskQueue().get(True)
                if url is None:  # end-marker?
                    self.resultQueue.put(self)  # report being finished
                f = urllib.urlopen(url)
                contents = f.read()
                f.close()
                self.resultQueue.put(contents)
            except Exception, e:
                self.resultQueue.put(e)

def get_files(urls):
    taskQueue = Queue()
    for url in urls:
        taskQueue.put(url)
    resultQueue = Queue()
    workers = set([ Worker(taskQueue, resultQueue) for i in range(4) ])
    for worker in workers:
        worker.start()
        taskQueue.put(None)  # one end marker for each worker thread
    while workers:
        result = resultQueue.get(True)
        if result in workers:
            workers.remove(result)
        else:
            yield result</description>
		<content:encoded><![CDATA[<p>I agree with Alastair.</p>
<p>class Worker(threading.Thread):<br />
    def __init__(self, taskQueue, resultQueue):<br />
        self.taskQueue = taskQueue<br />
        self.resultQueue = resultQueue<br />
        super(threading.Thread, self).__init__()<br />
    def run(self):<br />
        while True:  # until end marker found<br />
            try:<br />
                url = self.taskQueue().get(True)<br />
                if url is None:  # end-marker?<br />
                    self.resultQueue.put(self)  # report being finished<br />
                f = urllib.urlopen(url)<br />
                contents = f.read()<br />
                f.close()<br />
                self.resultQueue.put(contents)<br />
            except Exception, e:<br />
                self.resultQueue.put(e)</p>
<p>def get_files(urls):<br />
    taskQueue = Queue()<br />
    for url in urls:<br />
        taskQueue.put(url)<br />
    resultQueue = Queue()<br />
    workers = set([ Worker(taskQueue, resultQueue) for i in range(4) ])<br />
    for worker in workers:<br />
        worker.start()<br />
        taskQueue.put(None)  # one end marker for each worker thread<br />
    while workers:<br />
        result = resultQueue.get(True)<br />
        if result in workers:<br />
            workers.remove(result)<br />
        else:<br />
            yield result</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multi-threading in Python by Python Threading &#124; edgeArchitect</title>
		<link>http://www.artfulcode.net/articles/multi-threading-python/comment-page-1/#comment-3762</link>
		<dc:creator>Python Threading &#124; edgeArchitect</dc:creator>
		<pubDate>Sat, 14 Jan 2012 10:07:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/multi-threading-python/#comment-3762</guid>
		<description>[...] Artful Code Youtube Video [...]</description>
		<content:encoded><![CDATA[<p>[...] Artful Code Youtube Video [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multi-threading in Python by Alastair</title>
		<link>http://www.artfulcode.net/articles/multi-threading-python/comment-page-1/#comment-3749</link>
		<dc:creator>Alastair</dc:creator>
		<pubDate>Wed, 21 Dec 2011 20:06:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/multi-threading-python/#comment-3749</guid>
		<description>Perhaps I am missing something but why are you putting the threads themselves in a queue? This seems like a very strange use of queues. Also you end up creating one thread per task which is very wasteful.

Personally I would stick the jobs to be performed (in this case URLs to be downloaded) in a queue then create n (in this case 4) threads to work through that queue. If necessary, these threads can place the results in another queue to be processed by some other number of consumer threads.

This solution would have the huge advantage that jobs can be added as you go along, which is absolutely crucial if you want to chain a few of these things together.

I also do not understand the point of creating a Thread class to replace the get_files function. Ostensibly you do this to make things simpler, but actually I think it&#039;s more complicated (at least for illustration purposes). Potentially you might want your tasks to be objects so your pool of threads would take task objects from a queue, do something to those objects and put the &quot;finished&quot; objects into another queue for further processing. But I can&#039;t see why you need your tasks to be thread objects.</description>
		<content:encoded><![CDATA[<p>Perhaps I am missing something but why are you putting the threads themselves in a queue? This seems like a very strange use of queues. Also you end up creating one thread per task which is very wasteful.</p>
<p>Personally I would stick the jobs to be performed (in this case URLs to be downloaded) in a queue then create n (in this case 4) threads to work through that queue. If necessary, these threads can place the results in another queue to be processed by some other number of consumer threads.</p>
<p>This solution would have the huge advantage that jobs can be added as you go along, which is absolutely crucial if you want to chain a few of these things together.</p>
<p>I also do not understand the point of creating a Thread class to replace the get_files function. Ostensibly you do this to make things simpler, but actually I think it&#8217;s more complicated (at least for illustration purposes). Potentially you might want your tasks to be objects so your pool of threads would take task objects from a queue, do something to those objects and put the &#8220;finished&#8221; objects into another queue for further processing. But I can&#8217;t see why you need your tasks to be thread objects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multi-threading in Python by SrijonLab</title>
		<link>http://www.artfulcode.net/articles/multi-threading-python/comment-page-1/#comment-3748</link>
		<dc:creator>SrijonLab</dc:creator>
		<pubDate>Wed, 21 Dec 2011 07:48:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/multi-threading-python/#comment-3748</guid>
		<description>cons_thread = threading.Thread( target=consumer, args=(q, len(files)) &quot;)&quot; is missing so put it</description>
		<content:encoded><![CDATA[<p>cons_thread = threading.Thread( target=consumer, args=(q, len(files)) &#8220;)&#8221; is missing so put it</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multi-threading in Python by SrijonLab</title>
		<link>http://www.artfulcode.net/articles/multi-threading-python/comment-page-1/#comment-3747</link>
		<dc:creator>SrijonLab</dc:creator>
		<pubDate>Wed, 21 Dec 2011 07:47:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/multi-threading-python/#comment-3747</guid>
		<description>and 
cons_thread = threading.Thread( target=consumer, args=(q, len(files)) &quot;)&quot; This is Missing on The Script So Put it</description>
		<content:encoded><![CDATA[<p>and<br />
cons_thread = threading.Thread( target=consumer, args=(q, len(files)) &#8220;)&#8221; This is Missing on The Script So Put it</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multi-threading in Python by SrijonLab</title>
		<link>http://www.artfulcode.net/articles/multi-threading-python/comment-page-1/#comment-3746</link>
		<dc:creator>SrijonLab</dc:creator>
		<pubDate>Wed, 21 Dec 2011 07:45:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/articles/multi-threading-python/#comment-3746</guid>
		<description>You Have Error On Your Script...
Change  
&quot;for file in files:&quot; to 
&quot;for ufile in files:
   thread = FileGetter(ufile)&quot; 

and 

urllib.urlopen(self.url)</description>
		<content:encoded><![CDATA[<p>You Have Error On Your Script&#8230;<br />
Change<br />
&#8220;for file in files:&#8221; to<br />
&#8220;for ufile in files:<br />
   thread = FileGetter(ufile)&#8221; </p>
<p>and </p>
<p>urllib.urlopen(self.url)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Projects by Kanen Flowers</title>
		<link>http://www.artfulcode.net/projects/comment-page-1/#comment-3745</link>
		<dc:creator>Kanen Flowers</dc:creator>
		<pubDate>Sun, 18 Dec 2011 21:28:30 +0000</pubDate>
		<guid isPermaLink="false">http://wp.artfulcode.net/?page_id=87#comment-3745</guid>
		<description>Artful code modules are actually at GitHub (not Google Code) 
&lt;a href=&quot;https://github.com/LifeZero/artful-newlisp&quot; title=&quot;Artful Code&quot; rel=&quot;nofollow&quot;&gt;code repository&lt;/a&gt;

Also, the main page is at: &lt;a href=&quot;http://ScruffyThinking.com/artful/&quot; title=&quot;Scruffy Thinking&quot; rel=&quot;nofollow&quot;&gt;Scruffy Thinking&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Artful code modules are actually at GitHub (not Google Code)<br />
<a href="https://github.com/LifeZero/artful-newlisp" title="Artful Code" rel="nofollow">code repository</a></p>
<p>Also, the main page is at: <a href="http://ScruffyThinking.com/artful/" title="Scruffy Thinking" rel="nofollow">Scruffy Thinking</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Phorms by neyro.it - PHP Dev Stack</title>
		<link>http://www.artfulcode.net/phorms/comment-page-1/#comment-3742</link>
		<dc:creator>neyro.it - PHP Dev Stack</dc:creator>
		<pubDate>Wed, 30 Nov 2011 06:46:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.artfulcode.net/?page_id=608#comment-3742</guid>
		<description>[...] Phorms для работы с формами    This entry was posted in PHP and tagged PHP by neyronius. Bookmark the permalink. [...]</description>
		<content:encoded><![CDATA[<p>[...] Phorms для работы с формами    This entry was posted in PHP and tagged PHP by neyronius. Bookmark the permalink. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

