0

Is there a defined limit on the number of tkinter after events that can be pending?

This number can get big if for example a worker thread posts after events faster than tkinter can process them.

What happens if this limit is exceeded?

mcu
  • 3,302
  • 8
  • 38
  • 64
  • How do You think what would happen (if there was a limit in the first place (which I don't know but a certain set limit would be Your computer's memory))? it will crash (by logic at least) – Matiiss Apr 14 '21 at 18:20
  • @Matiiss: `tkinter` could for example discard new events or overwrite old pending ones. – mcu Apr 14 '21 at 18:48
  • _"What happens if this limit is exceeded?"_ - that should be trivial to figure out. Create a function that takes a second to complete, then call `after` repeatedly until tkinter crashes. – Bryan Oakley Apr 14 '21 at 19:33

1 Answers1

1

The limit is probably hardware related. There are different advice on how to use threads. Some say you shouldn't use threads at all and others are fine with it. Anyway, if your hardware can't afford your requested tasks your application will crash.

Tkinter schedules its after methods not exactly by time, it schedules it after a period of time and the task is on top of the list to do. So in fact, tkinter sets no limits to the tasks your hardware do.

For reference

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
  • 2
    Btw `tkinter`'s `.after` scripts are run in the thread where the `.mainloop()` was called. I don't know why you linked that stackoverflow answer. – TheLizzard Apr 14 '21 at 19:18
  • @TheLizzard well, just because its mentioned in the Question. Read carfully – Thingamabobs May 18 '21 at 14:48
  • So we are agreeing that tkinter doesn't use threads when running `.after` scripts. So my question is why did you link a stackoverflow answer that talks about the maximum number of threads? It seem unrelated – TheLizzard May 18 '21 at 15:10
  • *This number can get big if for example a worker thread posts after events* – Thingamabobs May 18 '21 at 15:28
  • Generally it is discouraged to use tkinter methods (including `.after(...)`) when using using threads. So if you follow that rule, you should only call tkinter methods from 1 thread (the main thread most of the time). – TheLizzard May 18 '21 at 15:30