Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!feed.xsnews.nl!border-2.ams.xsnews.nl!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'pygame': 0.05; 'sys': 0.05; 'definitions': 0.07; 'function,': 0.07; 'imports': 0.07; 'method,': 0.07; 'script,': 0.07; 'python': 0.08; '(it': 0.09; '0),': 0.09; 'dependency': 0.09; 'filename': 0.09; 'func': 0.09; 'globals': 0.09; 'run.': 0.09; 'subject:Processing': 0.09; 'throw': 0.09; 'tuple': 0.09; 'skip:[ 20': 0.12; 'things.': 0.12; 'def': 0.13; 'debugging': 0.13; 'received:209.85.210.174': 0.13; 'received:mail-iy0-f174.google.com': 0.13; 'argument': 0.15; 'class,': 0.15; 'skip:" 40': 0.15; '"from': 0.16; '###': 0.16; '(0,': 0.16; '0))': 0.16; 'arg': 0.16; 'classes)': 0.16; "doesn't.": 0.16; 'frame,': 0.16; 'globals.': 0.16; 'mean,': 0.16; 'pprint': 0.16; 'pygame.': 0.16; 'suggested.': 0.16; 'wrote:': 0.18; 'arguments': 0.18; 'functions,': 0.18; 'lines,': 0.18; 'working.': 0.18; 'help.': 0.19; 'cc:no real name:2**0': 0.20; 'checked': 0.21; 'trying': 0.21; '(most': 0.21; "aren't": 0.21; 'stuff': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'figure': 0.23; 'dictionary': 0.23; 'module,': 0.23; 'defined': 0.24; 'math': 0.24; 'cc:2**0': 0.24; 'keyword': 0.24; "python's": 0.24; 'traceback': 0.24; 'handles': 0.25; 'obviously': 0.25; 'code': 0.25; 'classes': 0.26; 'expect': 0.26; 'function': 0.27; 'import': 0.27; 'tried': 0.27; 'remote': 0.28; 'cc:addr:gmail.com': 0.28; 'raise': 0.28; 'skip:" 30': 0.28; 'work.': 0.28; 'pass': 0.29; 'print': 0.29; 'second': 0.29; 'error': 0.29; 'pm,': 0.29; 'skip:p 30': 0.29; 'class': 0.29; 'correct': 0.29; 'times.': 0.30; 'also.': 0.30; 'calculated': 0.30; 'modules,': 0.30; 'servers.': 0.30; 'typeerror:': 0.30; 'anyone': 0.31; "i've": 0.31; "didn't": 0.31; 'hi,': 0.32; 'familiar': 0.32; "can't": 0.32; "isn't": 0.33; 'message- id:@gmail.com': 0.33; 'header:User-Agent:1': 0.33; 'there': 0.33; 'object': 0.33; 'to:addr:python-list': 0.34; 'probably': 0.34; 'things': 0.34; 'calling': 0.34; 'curious': 0.34; 'last):': 0.34; '(not': 0.35; 'something': 0.35; 'be.': 0.35; 'modules': 0.35; 'supposed': 0.35; 'however,': 0.36; 'file': 0.36; 'shows': 0.37; 'variables': 0.37; 'skip:" 10': 0.37; 'two': 0.37; 'but': 0.37; 'run': 0.37; 'machine': 0.37; 'received:192': 0.37; 'received:google.com': 0.37; 'think': 0.37; 'could': 0.37; 'doing': 0.38; 'screen': 0.38; 'received:209.85': 0.38; 'getting': 0.38; 'processing': 0.39; 'else': 0.39; "couldn't": 0.39; 'setup': 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'more': 0.61; 'quick': 0.61; 'your': 0.61; 'provided': 0.62; 'connect': 0.62; 'results': 0.63; 'p.s.': 0.67; 'funny': 0.76; 'submit.': 0.84; 'timer': 0.84; 'together,': 0.84; 'traceback,': 0.84; 'local,': 0.91; 'arrangement': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=vdAl1pmdBNn9uGqtvEYrdVvkmOT/t4QROGIJ2yVOKBI=; b=dbaL4qY7kRJNGlaPGYxhVKxHzgBnq0QIATJSjvOrBe+aU9oiFyKPkErXUCcJ5mRRF3 2UxUpqac45RHicTG/v4koMelVptsWZ+ajL7sTjxPicax4ioQXEmFCdZsBvl5M1L+cCgZ rQTgGbOkKCxdGPXN3gjlU2NAY/q24a1SKKN6A= Date: Sun, 08 Jan 2012 18:02:55 -0600 From: David Hoese User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Parallel Processing References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: y.turgut@gmail.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 184 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326067374 news.xs4all.nl 6854 [2001:888:2000:d::a6]:37621 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18688 On 1/8/12 1:45 PM, Yigit Turgut wrote: > There are no imports other than defined on the script, which are; > > import pygame > import sys > import time > import math > import pp > > You are correct about trying to pass two functions and second one is > in place where a tuple of arguments supposed to be. But what if these > functions don't have any arguments ? I tested functions test1() and > test2() seperately ; they work. Once I figure out how to run these > functions simultaneously, I will add an argument to test2 and try then > on. My main goal is to simultaneously run two functions, one of them > has one argument the other doesn't. To get familiar with parallel > processing I am experimenting now without arguments and then I will > embed the code to my application. I am experimenting with the > 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 > global white > 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(end<5): > end = time.time() - start > print end > > ppservers = () > job_server = pp.Server(ppservers=ppservers) > print "Starting pp with", job_server.get_ncpus(), "workers" > > job1 = job_server.submit(test1()) > job2 = job_server.submit(test2()) > result = job1() > result2 = job2() > > print "Counting...", result2 > > job_server.print_stats() > > test1() works as expected (job1) but test2() doesn't work and I get > the following traceback ; > > Traceback (most recent call last): > File "fl.py", line 33, in > job1 = job_server.submit(test1()) > File "/usr/lib/python2.6/site-packages/pp.py", line 458, in submit > sfunc = self.__dumpsfunc((func, ) + depfuncs, modules) > File "/usr/lib/python2.6/site-packages/pp.py", line 629, in > __dumpsfunc > sources = [self.__get_source(func) for func in funcs] > File "/usr/lib/python2.6/site-packages/pp.py", line 696, in > __get_source > sourcelines = inspect.getsourcelines(func)[0] > File "/usr/lib/python2.6/inspect.py", line 678, in getsourcelines > lines, lnum = findsource(object) > File "/usr/lib/python2.6/inspect.py", line 519, in findsource > file = getsourcefile(object) or getfile(object) > File "/usr/lib/python2.6/inspect.py", line 441, in getsourcefile > filename = getfile(object) > File "/usr/lib/python2.6/inspect.py", line 418, in getfile > raise TypeError('arg is not a module, class, method, ' > TypeError: arg is not a module, class, method, function, traceback, > frame, or code object > > Error is related to test1 not having an argument. When I leave it > empty as following ; > > job1 = job_server.submit(test1,()) > > test1 doesn't run. When I do ; > > job1 = job_server.submit(test1()) > > Display works but I get; > > TypeError: arg is not a module, class, method, function, traceback, > frame, or code object (complete traceback same as above). > > And test2 doesn't work also. But when I do; > > job1 = job_server.submit(test1,()) > job2 = job_server.submit(test2()) > > I get test2 working but test1 not working. Obviously related to > argument arrangement in submit. Hi, I've never used pygame or Parallel Python, but I played around with the code you provided and did one of my favorite debugging techniques...I printed things out and read the output. So one thing I did was printed the globals before the function definitions and inside test1(). Which the first print shows what I expect from calling "print globals()", then inside test1() I only get functions, modules, and a few other things. So I checked the pp documentation and found this about the globals keyword: globals - dictionary from which all modules, functions and classes It also handles imports funny because I tried doing "from pprint import pprint" and it couldn't find it properly even though that's a function (it couldn't find a class that that function uses). So I think you'll have to pass things in as arguments or a dependency functions as others have suggested. There is also a 'modules' keyword that you can provide names of modules to import, which might help. And is there a reason you need to use Parallel Python and can't use something more simple like python's "multiprocessing" or the classic "os.fork()"? I understand that Parallel Python can run on remote servers in parallel...but how complicated is your program going to be? I got the following to work (not sure if its what you want): ### import pp def test1(): start = time.time() end = time.time() - start screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) timer = pygame.time.Clock() white = True 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(): start = time.time() end2= time.time() - start while(end2<5): end2 = time.time() - start print end2 ppservers = () job_server = pp.Server(ppservers=ppservers) job1 = job_server.submit(test1, modules=("pygame","time")) job2 = job_server.submit(test2, modules=("time",)) result = job1() result2 = job2() print result2 job_server.print_stats() ### However, I don't know if this will always work the way you want it to, depending on how you setup your Parallel Python servers. By that I mean, if you run this on any machine that isn't local, I think it will try to connect to that remote display when getting the pygame "screen". But again, I've never used pygame. And this was also a quick throw together, so you could probably pass in "start" and stuff like that so that it doesn't have to be calculated both times. Summary: Parallel Python doesn't handle global variables in a normal way (it doesn't like things that aren't functions, modules, or classes) so...don't use globals. Let me know if any of that didn't make sense. -Dave P.S. If anyone has any other results I would be curious to hear.