Avoiding long delays in scheduled function calls

49 views
Skip to first unread message

Mathieu

unread,
Jan 1, 2021, 6:49:22 AM1/1/21
to pyglet-users
Apologies if this is obviously out of pyglet's scope/objectives.

Function calls triggered by pyglet.clock.schedule_interval() seem to occur at extremely variable time intervals after the pyglet window is hidden/minimized (this is on macOS Catalina, in case it matters).

Below is a minimal example that should print out a number not much greater than 0.5 every half second. Instead, after a few seconds of the window being minimized, calls are delayed by up to 10 seconds.

I'm (baselessly) assuming this is because pyglet is designed to function with lower priority when the window is not visible. I dont really care if my functions calls occur every 0.6 seconds instead of 0.5, but a 10s lag seems unreasonably large.

Is there a simple way to ensure pyglet maintains a high priority and/or does not drastically alter the frequency of scheduled calls?

----
import pyglet
window = pyglet.window.Window(width = 128, height = 128)

@window.event
def on_draw():
    window.clear()

def foo(t):
    print(t)

pyglet.clock.schedule_interval(foo, 0.5)
pyglet.app.run()
----

Typical output below:

----
0.5010913940000137
8.22102221900002
10.501081690999968
10.501448707999998
10.501421234999953
3.7303194810000377
10.501095133000035
0.5011976460000369
10.501220476999947
10.501225187000045
4.144422970999926
----

Chris Norman

unread,
Jan 1, 2021, 7:11:19 AM1/1/21
to pyglet-users
Hi,
I just tested your code on Windows 10, and I don't get the problems you describe. My times didn't get about 0.52 seconds haha.

Wonder if it's another gift from Mac OS?

Take care,

Chris Norman



--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyglet-users/b83ecc7f-128f-427f-9430-78157d292d73n%40googlegroups.com.

Mathieu Daëron

unread,
Jan 1, 2021, 7:38:30 AM1/1/21
to pyglet...@googlegroups.com
Interesting, thanks. I'll test this on a Raspberry Pi and report the results.

On 1 Jan 2021, at 13:11, 'Chris Norman' via pyglet-users <pyglet...@googlegroups.com> wrote:



nmcel...@gmail.com

unread,
Jan 2, 2021, 8:21:33 AM1/2/21
to pyglet-users
pyglet happiest if you keep a window open.
Reply all
Reply to author
Forward
0 new messages