Esempio n. 1
0
    def run(self, call_interval=1 / 10., installSignalHandlers=True):
        """Start the Pyglet event loop and Twisted reactor."""

        if call_interval is 0:
            warnings.warn(
                "CALL INTERVAL SET TO 0. THIS WILL PREVENT WINDOWS FROM CLOSING OR UPDATING"
            )
        # Create a queue to hold Twisted events that will be executed
        # before stopping Twisted in the event that Pyglet has been stopped.
        self._postQueue = Queue.Queue()
        self._twistedQueue = Queue.Queue()

        if not hasattr(self, "pygletEventLoop"):
            log.msg("No Pyglet event loop registered. Using the default.")
            self.registerPygletEventLoop(
                EventLoop(self._twistedQueue, call_interval))
        else:
            self.pygletEventLoop.register_twisted_queue(
                self._twistedQueue, call_interval)

        # Start the Twisted thread.
        self.interleave(self._runInMainThread,
                        installSignalHandlers=installSignalHandlers)

        # Add events to handle Pyglet/Twisted shutdown events
        self.addSystemEventTrigger("after", "shutdown", self._stopPyglet)
        self.addSystemEventTrigger("after", "shutdown",
                                   lambda: self._postQueue.put(None))

        self.pygletEventLoop.run()

        # Now that the event loop has finished, remove
        # it so that further Twisted events are added to
        # the shutdown queue, and are dealt with below.
        del self.pygletEventLoop

        if not self._stopping:
            # The Pyglet event loop is no longer running, so we monitor the
            # queue containing Twisted events until all events are dealt with.
            self.stop()
            while 1:
                try:
                    f = self._postQueue.get(timeout=0.01)
                except Queue.Empty:
                    continue
                else:
                    # 'None' on the queue signifies the last Twisted event.
                    if f is None:
                        break
                    try:
                        f()
                    except:
                        log.err()
Esempio n. 2
0
    This is a convenience function, equivalent to::

        event_loop.exit()

    '''
    event_loop.exit()

from pyglet.app.base import EventLoop
from pyglet import compat_platform
if _is_epydoc:
    from pyglet.app.base import PlatformEventLoop
else:
    if compat_platform == 'darwin':
        from pyglet import options as pyglet_options
        if pyglet_options['darwin_cocoa']:
            from pyglet.app.cocoa import CocoaEventLoop as PlatformEventLoop
        else:
            from pyglet.app.carbon import CarbonEventLoop as PlatformEventLoop
    elif compat_platform in ('win32', 'cygwin'):
        from pyglet.app.win32 import Win32EventLoop as PlatformEventLoop
    else:
        from pyglet.app.xlib import XlibEventLoop as PlatformEventLoop



event_loop = EventLoop()

platform_event_loop = PlatformEventLoop()