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


Groups > comp.lang.python > #52464

Re: multithreading in python

From Terry Reedy <tjreedy@udel.edu>
Subject Re: multithreading in python
Date 2013-08-13 11:51 -0400
References <dac9bb94-a1e2-410b-b925-445a2c8b66a0@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.540.1376409084.1251.python-list@python.org> (permalink)

Show all headers | 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