The following code fails silently (the child process segfaults):

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
from multiprocessing import Process
import pyglet

def run():
    window = pyglet.window.Window()
    pyglet.app.run()

import pyglet.gl
p = Process(target=run)
p.start()
p.join()
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

Commenting out the "import pyglet.gl" line fixes the problem. Setting
"pyglet.options["shadow_window"] = False" fixes it too, so this is
related to the shadow window created by pyglet when importing
pyglet.gl [1]

I don't understand why this problem occurs, maybe some issue related
to hardware resources when copying the shadow context created by
pyglet from the parent to the child process ? The fork() manpage says
nothing about this, and apart from random people telling me this is a
"bad idea" I wasn't able to find any information.

The fact that pyglet fails silently made this problem difficult to
track down, maybe an explicit error message could be added by patching
os.fork() with something like this ?

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
import os
import sys
import pyglet

parent_pid = os.getpid()
os_fork = None

def _fork():
    if "pyglet.gl" in sys.modules and pyglet.options["shadow_window"]:
        raise RuntimeError("you can't fork a new process after
pyglet.gl has "
                "been imported, please set
pyglet.options["shadow_window"] to "
                "False")
    return os_fork()

if "fork" in dir(os) and os.fork != _fork:
    os_fork = os.fork
    os.fork = _fork
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

[1] 
http://www.pyglet.org/doc/programming_guide/sharing_objects_between_contexts.html

Cheers,
--
Lup

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to