Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18680
| Date | 2012-01-08 17:02 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: Parallel Processing |
| References | <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com> <mailman.4524.1326033306.27778.python-list@python.org> <402bb451-9986-4a26-b606-6a1c3429f98e@s18g2000vby.googlegroups.com> <mailman.4525.1326038463.27778.python-list@python.org> <3161f7ec-feb6-41ef-b73d-bb22e3e7704e@n6g2000vbg.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4530.1326060156.27778.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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