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


Groups > comp.lang.python > #18671

Re: Parallel Processing

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!rt.uk.eu.org!news-transit.tcx.org.uk!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
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; 'else:': 0.03; 'args': 0.05; 'pygame': 0.05; 'stuff.': 0.05; 'sys': 0.05; '0),': 0.09; 'it;': 0.09; 'nameerror:': 0.09; 'subject:Processing': 0.09; 'tuple': 0.09; 'output': 0.10; 'am,': 0.12; 'def': 0.13; 'argument': 0.15; 'skip:" 40': 0.15; 'tries': 0.15; '(0,': 0.16; '(eg.': 0.16; '0))': 0.16; '46,': 0.16; 'multithread': 0.16; 'traceback.': 0.16; 'typo': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'arguments': 0.18; 'occurred': 0.18; 'appears': 0.19; 'cc:no real name:2**0': 0.20; 'trying': 0.21; '(most': 0.21; 'header:In-Reply-To:1': 0.22; 'url:view': 0.23; 'interface': 0.23; 'complete,': 0.23; 'objects,': 0.23; 'defined': 0.24; 'math': 0.24; 'cc:2**0': 0.24; 'suspect': 0.24; 'times,': 0.24; 'traceback': 0.24; 'code': 0.25; 'candidate': 0.26; 'testing': 0.26; 'function': 0.27; 'import': 0.27; 'variable': 0.28; 'all,': 0.28; 'raise': 0.28; 'print': 0.29; 'cc:addr:python.org': 0.29; 'second': 0.29; 'error': 0.29; 'skip:p 30': 0.29; 'arguments.': 0.30; 'typeerror:': 0.30; 'anyone': 0.31; 'source': 0.31; 'does': 0.32; 'idea': 0.32; 'header:User-Agent:1': 0.33; 'that,': 0.33; 'there': 0.33; 'it.': 0.34; 'creates': 0.34; 'calling': 0.34; 'declared': 0.34; 'function.': 0.34; 'last):': 0.34; 'matter,': 0.34; 'statement,': 0.34; 'something': 0.35; 'external': 0.35; 'post': 0.36; 'file': 0.36; 'similar': 0.36; 'starting': 0.36; 'example,': 0.37; 'thread': 0.37; 'variables': 0.37; 'two': 0.37; 'but': 0.37; 'run': 0.37; 'received:192': 0.37; 'using': 0.38; 'screen': 0.38; 'processing': 0.39; 'should': 0.39; 'else': 0.39; "it's": 0.40; 'received:192.168': 0.40; 'once': 0.60; 'more': 0.61; 'your': 0.61; 'full': 0.62; 'detected': 0.63; 'ever': 0.65; 'website': 0.65; 'here': 0.65; 'here.': 0.66; 'show': 0.67; 'stated': 0.68; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; '08:23': 0.84; 'hunt': 0.84; 'of;': 0.84; 'timer': 0.84; 'dozens': 0.91
Date Sun, 08 Jan 2012 09:34:53 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15
MIME-Version 1.0
To Yigit Turgut <y.turgut@gmail.com>
Subject Re: Parallel Processing
References <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com>
In-Reply-To <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:7IZ63m7yiilYUVQuFxi/2MYphXSlmkZQnoN0mH/IER4 TjO63rEo0TmwnN40Ifdvmmsm7Mg9yQfyfFd8nSbOR4caG1ZoRG tFfZYd2roVyyK3R6ELrPUwCL0X6lVNo+Msxj7bWWgv/m0l2cnP oO7y3C5Z/cMIi+JMzIYnTVQBrFJQ1yb44/8vx46HpUFpjgNh9w TewveucUSMpRIThQXn2Q1+RYkYz9EPQ/zDF/sj/PVvKDbNRt1/ B9gFapy4HcRVrthZTM2jWw0hWt8UJ0QZdclJFyxujhcJfYCdX1 ahZZunBhrbv0iRDJR0dx4jur9Xig3M6EN9PZTK2AphCNhKHqCf j8ciAVmsMJNKtvJdXaoo=
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
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.4524.1326033306.27778.python-list@python.org> (permalink)
Lines 103
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1326033306 news.xs4all.nl 6901 [2001:888:2000:d::a6]:50357
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18671

Show key headers only | View raw


On 01/08/2012 08:23 AM, Yigit Turgut wrote:
> Hi all,
>
> I am trying to run two functions at the same time with Parallel
> Processing (pp) as following ;
>
> import pygame
> import sys
> import time
> import math
> import pp
>
> screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
> timer = pygame.time.Clock()
> white = True
> start = time.time()
> end = time.time() - start
>
> def test1():
>    global end
>    while(end<5):
>      end = time.time() - start
>      timer.tick(4) #FPS
>      screen.fill((255,255,255) if white else (0, 0, 0))
>      white = not white
>      pygame.display.update()
>
> def test2():
>    global end
>    while(end2<5):
>      end2 = time.time() - start
>      print end
>
> ppservers = ()
>
> if len(sys.argv)>  1:
>      ncpus = int(sys.argv[1])
>      # Creates jobserver with ncpus workers
>      job_server = pp.Server(ncpus, ppservers=ppservers)
> else:
>      # Creates jobserver with automatically detected number of workers
>      job_server = pp.Server(ppservers=ppservers)
> print "Starting PP with", job_server.get_ncpus(), "workers"
>
> job1 = job_server.submit(test1,test2)
> result = job1()
>
> And the output is ;
>
> Starting PP with 2 workers
> Traceback (most recent call last):
>    File "fl.py", line 46, in<module>
>      job1 = job_server.submit(test1,test2)
>    File "/usr/lib/python2.6/site-packages/pp.py", line 402, in submit
>      raise TypeError("args argument must be a tuple")
> TypeError: args argument must be a tuple
>
>
> When I change job1 to just to see if it will run one function only;
> job1 = job_server.submit(test1)
>
> I get an output of;
>
> NameError: global name 'end' is not defined
>
> end variable is defined as global but I get a NameError. Anyone has an
> idea what's going on ?
First, please tell us about any external dependencies (eg. imports).  
Pygame may not matter, since there are many people here using it, but 
each of us has to hunt down something that does parallel processing with 
an interface similar to what you're using.  For the next person, the 
most likely candidate out of the dozens available is:
http://www.parallelpython.com/

Your problem, as stated in the raise statement, is that the submit 
method is expecting a tuple for its "args argument".  Now I had to go to 
the website to find an example, but it appears that your second argument 
should have been a tuple of the arguments for your function.  See
*      submit*(self, func, args=(), depfuncs=(), modules=(), 
callback=None, callbackargs=(), group='default', globals=None)

on page: http://www.parallelpython.com/content/view/15/30/#API

So you're passing it two function objects, and the second one is in the 
place where it's expecting a tuple of arguments.  Apparently you should 
be calling submit multiple times, once for each function.

As for the error you get when you do that, please post the full 
traceback. I suspect that the message you did post has a typo in it, or 
that the error occurred when your source code was not as you show it 
here.  You have two variables end and end2, and only the first one is 
ever declared global.  func2() should get a different error when you run 
it; since it tries to use a local end2 before defining it.

I recommend always testing your code with a single thread before trying 
to launch more complex multithread stuff.  Just call func() and func2(), 
and see if they complete, and get reasonable answers.

-- 

DaveA

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


Thread

Parallel Processing Yigit Turgut <y.turgut@gmail.com> - 2012-01-08 05:23 -0800
  Re: Parallel Processing Dave Angel <d@davea.name> - 2012-01-08 09:34 -0500
    Re: Parallel Processing Yigit Turgut <y.turgut@gmail.com> - 2012-01-08 07:45 -0800
      Re: Parallel Processing Chris Angelico <rosuav@gmail.com> - 2012-01-09 03:00 +1100
        Re: Parallel Processing Yigit Turgut <y.turgut@gmail.com> - 2012-01-08 08:39 -0800
          Re: Parallel Processing Dave Angel <d@davea.name> - 2012-01-08 17:02 -0500

csiph-web