Using the python multiprocessing module for IO with pygame on Mac OS 10.7

前端 未结 3 741
刺人心
刺人心 2021-02-13 12:15

I use pygame for running experiments in cognitive science, and often I have heavy I/O demands so I like to fork off these tasks to separate processes (when using a multi-core ma

相关标签:
3条回答
  • 2021-02-13 12:33

    Have you tried using threads instead of processes? I've had issues before using the python multiprocessing module in OS X. http://docs.python.org/library/threading.html

    0 讨论(0)
  • 2021-02-13 12:42

    Maybe you should initialize the pygame (which initialize SDL-> OpenGL) in each forked (child) process like in sample:

    import multiprocessing
    
    def f():
      import pygame
      pygame.init()
    
      while True:
        pygame.event.pump()
    
    if __module__ == "__main__"
      p = multiprocessing.Process(target=f)
      p.start()
    
      import pygame
      pygame.init()
    
      while True:
        pygame.event.pump()
    
    0 讨论(0)
  • 2021-02-13 12:42

    Try this link:

    http://www.slideshare.net/dabeaz/an-introduction-to-python-concurrency#btnPrevious

    It may help. The problem is that you are creating a process that never stops. This should be declared as a daemon:

    p = multiprocessing.Process(target=f)
    p.daemon = True
    p.start()
    

    Not sure if this will solve the problem, I'm just learning about the multiprocessing module as I'm posting this.

    0 讨论(0)
提交回复
热议问题