Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52464

Re: multithreading in python

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'deprecated': 0.09; 'filename': 0.09; 'path)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; '"r")': 0.16; "'rb')": 0.16; 'block.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:skip:m 10': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'not,': 0.20; 'spread': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'skip:" 30': 0.26; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '(this': 0.29; 'am,': 0.29; 'statement': 0.30; 'skip:i 60': 0.31; 'file': 0.32; 'doing': 0.36; 'problems': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'aside': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; 'skip:i 50': 0.60; 'skip:o 30': 0.61; 'received:173': 0.61; 'email addr:gmail.com': 0.63; 'different': 0.65; 'results': 0.69; 'score': 0.74; "'with'": 0.84; 'closes': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: multithreading in python
Date Tue, 13 Aug 2013 11:51:13 -0400
References <dac9bb94-a1e2-410b-b925-445a2c8b66a0@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7
In-Reply-To <dac9bb94-a1e2-410b-b925-445a2c8b66a0@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.540.1376409084.1251.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1376409084 news.xs4all.nl 15873 [2001:888:2000:d::a6]:43696
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52464

Show key headers only | View raw


On 8/13/2013 4:06 AM, samaneh.yahyapour@gmail.com wrote:

Aside from the other comments...

>      def item_thread(self):
>          imageAnalyzer=ctypes.CDLL("../so/image_process.so")
>          imageAnalyzer.aref_img_score_init("/opt/amniran/etc/face.xml", "/opt/amniran/etc/porn.xml")
>          for filename in os.listdir("../script/images/"):
>              if filename[-4:] == ".jpg" or filename[-4:] == ".png" or filename[-4:] == ".gif" or filename[-5:] == ".jpeg"    :
>
>                  path = "../script/images/%s"%filename
>
>                  fo = file(path, "r")

Use 'open' instead of the deprecated 'file' (removed in 3.x) and use it 
with a 'with' statement (this is now standard). This closes the file at 
the end of the block. Not doing so can cause problems on other 
implementations.

                 with open(path, 'rb') as fo:
>                  content = fo.read()

>                  score = imageAnalyzer.score_image(content, len(content))
>                  print "%d : %s " %(score, path)
>          print "ENDDDDDDDDDDDDDDDDDDDDDDDDDDDD"

Do you know how to use queue.Queue to spread work to multiple worker 
threads so each processes different files (and to collect results from 
multiple threads).? (If not, read doc.)

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

multithreading in python samaneh.yahyapour@gmail.com - 2013-08-13 01:06 -0700
  Re: multithreading in python Steven D'Aprano <steve@pearwood.info> - 2013-08-13 08:38 +0000
  Re: multithreading in python Dave Angel <davea@davea.name> - 2013-08-13 11:22 +0000
  Re: multithreading in python Dave Angel <davea@davea.name> - 2013-08-13 11:40 +0000
  Re: multithreading in python Terry Reedy <tjreedy@udel.edu> - 2013-08-13 11:51 -0400

csiph-web