# Package pyglet.app

Application-wide functionality.

Most applications need only call run after creating one or more windows to begin processing events. For example, a simple application consisting of one window is:

    from pyglet import app
    from pyglet import window

    win = window.Window()
    app.run()

To handle events on the main event loop, instantiate it manually. The following example exits the application as soon as any window is closed (the default policy is to wait until all windows are closed):

    event_loop = app.EventLoop()

    @event_loop.event
    def on_window_close(window):
        event_loop.exit()

Since: pyglet 1.1

## Classes

| WeakSet Set of objects, referenced weakly.
| EventLoop The main run loop of the application.

## Functions

| run() Begin processing events, scheduled functions and window updates.
| exit() Exit the application event loop.

## Variables

| displays = `WeakSet()`
| windows = `WeakSet()`
| event_loop = `None`
| __package__ = ``'``pyglet.app``'``

## Function Details

### run

run()

Begin processing events, scheduled functions and window updates.

This is a convenience function, equivalent to:

    EventLoop().run()

### exit

exit()

Exit the application event loop.

Causes the application event loop to finish, if an event loop is currently running. The application may not necessarily exit (for example, there may be additional code following the run invocation).

This is a convenience function, equivalent to:

    event_loop.exit()