Can pyglet run in new thread?

2.3k Views Asked by At

I would like to run pyglet in a separate thread so that I can implement a user interface for input without being blocked by pyglet.app.run().

import pyglet
class Window(pyglet.window.Window):
    def __init__(self):
        pyglet.window.Window.__init__(self, visible=True)
        self.push_handlers(on_draw=self.on_draw)
        self.im = pyglet.resource.image('image.jpg')
        pyglet.app.run()

    def on_draw(self):
        self.clear()

import threading
class Thread(threading.Thread):
    def run(self):
        w = Window()

Running

Window()

works fine. However, running

t = Thread()
t.start()

results in Segmentation fault (core dumped), which is caused by the call to pyglet.resource.image(). Omitting that call eliminates the problem.

Specifically, what is causing this problem, and how can I correct it? More generally, what is the recommended way to render a window using pyglet while allowing for other program execution? Is there a better way to do this?

0

There are 0 best solutions below