1

I'm trying to parallelize a code in Python but I'm having some problems. This is the part of the code:

survivor = Survivor(32*2, 32*4)   
if rank == 1:
    a = 'audio/zombie_theme.ogg'
    b = 'images/dungeon.jpg'
    c = 'images/dead.jpg'
    d = survivor.movement()
else:
    a = None
    b = None
    c = None
    d = None

a = comm.bcast(a, root=1)
b = comm.bcast(b, root=1)
c = comm.bcast(c, root=1)
d = comm.bcast(d, root=1)

if rank == 0:
    pygame.mixer.music.load(a)
    pygame.mixer.music.play(-1)
    pygame.display.set_caption('Zombie Game')
    screen = pygame.display.set_mode((display_width,display_height))
    Tile.pre_init(screen)
    clock = pygame.time.Clock()
    dungeon = pygame.image.load(b)

    keepPlaying = True
    while keepPlaying:

        screen.blit(dungeon, (0,0))
        Zombie.spawn(total_frames, FPS)
        Zombie.update(screen, survivor)
        d

When I call d in the last line, shouldn't it call survivor.movement() defined in process 1? When I run the game, my main character does not move, as it's supposed to do. But, when I remove d from everywhere and put survivor.movement() in the last line, it works as expected. Could anybody help me?

4

1 回答 1

2
d = survivor.movement

删除花括号。当您编写 d = motion() 时,您实际上将 d 分配给任何运动返回,而不是函数本身。

于 2015-07-15T18:27:10.617 回答