Path: csiph.com!backup.pasdenom.info!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'algorithm': 0.04; 'languages.': 0.04; 'say,': 0.05; 'subject:Python': 0.06; 'elegant': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subtle': 0.09; 'api': 0.11; 'python': 0.11; 'jan': 0.12; 'thread': 0.14; '(there': 0.16; 'blocking': 0.16; 'readable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:Java': 0.16; 'task.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'library': 0.18; 'restrictions': 0.19; 'written': 0.21; 'header:User-Agent:1': 0.23; 'typical': 0.24; 'java': 0.24; 'looks': 0.24; 'holds': 0.26; 'nearly': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "i'm": 0.30; 'code': 0.31; 'trivial': 0.31; 'class': 0.32; 'interface': 0.32; 'run': 0.32; 'worked': 0.33; 'third': 0.33; 'but': 0.35; 'add': 0.35; 'library.': 0.36; 'module.': 0.36; 'done': 0.36; 'should': 0.36; 'so,': 0.37; 'level': 0.37; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'problems.': 0.60; 'hope': 0.61; 'full': 0.61; 'received:173': 0.61; 'high': 0.63; 'more': 0.64; 'different': 0.65; 'here': 0.66; 'jobs': 0.68; 'safe': 0.72; 'therefore': 0.72; 'hoping': 0.75; 'heavy': 0.81; 'lifting': 0.84; 'received:fios.verizon.net': 0.84; 'race': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Multi-threading in Python vs Java Date: Fri, 11 Oct 2013 15:53:41 -0400 References: <46669eab-49f4-4daf-a410-abfbe9e87fc3@googlegroups.com> <6d35b728-85c2-4fc0-bbc8-6c033bdfcfb0@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:24.0) Gecko/20100101 Thunderbird/24.0 In-Reply-To: <6d35b728-85c2-4fc0-bbc8-6c033bdfcfb0@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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381521241 news.xs4all.nl 16006 [2001:888:2000:d::a6]:39711 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56704 On 10/11/2013 4:41 AM, Peter Cacioppi wrote: > I should add that the computational heavy lifting is done in a third party library. So a worker thread looks roughly like this (there is a subtle race condition I'm glossing over). > > while len(jobs) : > job = jobs.pop() > model = Model(job) # Model is py interface for a lib written in C > newJobs = model.solve() # This will take a long time > for each newJob in newJobs : > jobs.add(newJob) > > Here jobs is a thread safe object that is shared across each worker thread. It holds a priority queue of jobs that can be solved in parallel. > > Model is a py class that provides the API to a 3rd party library written in C.I know model.solve() will be the bottleneck operation for all but trivial problems. > > So, my hope is that the GIL restrictions won't be problematic here. That is to say, I don't need **Python** code to ever run concurrently. I just need Python to allow a different Python worker thread to execute when all the other worker threads are blocking on the model.solve() task. Once the algorithm is in full swing, it is typical for all the worker threads should be blocking on model.Solve() at the same time. > > It's a nice algorithm for high level languages. Java worked well here, I'm hoping py can be nearly as fast with a much more elegant and readable code. Given that model.solve takes a 'long time' (seconds, at least), the extra time to start a process over the time to start a thread will be inconsequential. I would therefore look at the multiprocessing module. -- Terry Jan Reedy