pyglet: Update interval when window is not visible

Hi,

I’m seeing that when my pyglet application’s UI window is not visible (e.g. hidden by other full-screen windows) then the update interval temporarily goes up from the one set for the application, e.g.:

pyglet.clock.schedule_interval(self.update, 1/30)

― to almost exactly one second. For anywhere between 5 to 19 update cycles. After that amount of update cycles which varies from experiment to experiment, it resumes its normal rate. And the same when I click the window’s minimize button and it minimizes ― several update cycles will last approximately exactly one second, before returning to the normal update rate.

The update rate reverts to normal after those several update cycles, while the window is still minimized or completely covered, the return to the normal update rate is not due to unhiding the window.

I’m just wondering if that’s in correspondence to any known phenomena related to window managers, or whether off the top of your head you’d expect different behavior if upgrading from pyglet 2.0.5 to the latest. I recall that orthogonally, 2.0.9 had introduced new levers for finer control of redraws, not updates.

This is on Wayland.

Thanks!


image

  • the yellows are the update-to-update interval, the infinitesimal blues at the bottom are the draw callback execution durations ― the latter do not change during the same time that the update-to-update interval spikes to one second.

  • during the same time, the time spent inside my update callbacks doesn’t change either:

image


As my application can be extremely sensitive to such large deviations, and can be assumed to be covered by other windows from time to time, I have instrumented it to easily view the times spent both within major functions, as well as the call-to-call intervals at which the callbacks are being called.

* in these runs, my update callback takes a little more than the requested udpate interval, which makes pyglet’s scheduler invoke the next update callback as soon as the previous one finished (which I confirm with other measurements not included above).

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

It’s accurate to say that pyglet’s clock and event dispatchers have not been heavily tested in multithreaded cases, and we don’t really support that, but it will be revisited if/when the no-GIL Python builds make it out.

Events can be dispatched from threads, but not if the handlers are acting upon any OpenGL backed objects (sprites, text). There is a way to dispatch events to the main thread. It’s not publicly documented, however.

Normal event dispatching:

self.dispatch_event('event_name', *args)

Post event to main thread:

# self being the class instance that mixes in EventDispatcher.
pyglet.app.platform_event_loop.post_event(self, 'event_name', *args)

Generally speaking threading is fine, but it’s OpenGL itself that doesn’t mesh well with it. There isn’t anything we can do about that on the pyglet side. pyglet uses threading internally for other things, like audio and controllers, but you can’t reliably update any OpenGL backed objects from those threads.