Parallel Processing

Dave Angel d at davea.name
Sun Jan 8 17:02:21 EST 2012


On 01/08/2012 11:39 AM, Yigit Turgut wrote:
>
> screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
> timer = pygame.time.Clock()
> white = True
> start = time.time()
> end = time.time() - start
> end2= 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 end2
>    while(end2<5):
>      end2 = time.time() - start
>      print end2
>
> ppservers = ()
> job_server = pp.Server(ppservers=ppservers)
>
> job1 = job_server.submit(test1, (), globals=globals())
> job2 = job_server.submit(test2, (), globals=globals())
> result = job1()
> result2 = job2()
>
> print  result2
>
> job_server.print_stats()
>
> This *supposed to* print values of 'end' and simultaneously execute
> test1. Eventhough I set globals parameter and nothing seems to be
> wrong this code generates the following traceback ;
>
> Starting pp with 2 workers
> An error has occured during the function execution
> Traceback (most recent call last):
>    File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
>      __result = __f(*__args)
>    File "<string>", line 4, in test1
> NameError: global name 'end' is not defined
> An error has occured during the function execution
> Traceback (most recent call last):
>    File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
>      __result = __f(*__args)
>    File "<string>", line 3, in test2
> NameError: global name 'end2' is not defined
>
> How can this be, what am I missing ?
I don't see anything on the http://www.parallelpython.com 
<http://www.parallelpython.com/> website that indicates how it handles 
globals.  Remember this is creating a separate process, so it can't 
literally share the globals you have.  i would have expected it to 
pickle them when you say globals=globals(), but I dunno. In any case, I 
can't see any value in making end global with the "global" statement.  
I'd move the end= line inside the function, and forget about making it 
global.

The other thing you don't supply is a list of functions that might be 
called by your function.  See the depfuncs argument.  It probably 
handles all the system libraries, but I can't see how it'd be expected 
to handle pygame.

With the limited information supplied by the website, I'd experiment 
first with simpler things.  Make two functions that are self-contained, 
and try them first.  No global statements, and no calls to pygame.  
After that much worked, then I'd try adding arguments, and then return 
values.

Then i'd try calling separate functions (declaring them in depfuncs).  
And finally I'd try some 3rd party library.


-- 

DaveA




More information about the Python-list mailing list