Python sched.scheduler exceeds max recursion depth

后端 未结 2 1962
感动是毒
感动是毒 2021-02-10 10:03

I have recently started learning Python and part of the simple app I am making includes a timer with a hh:mm:ss display running in its own thread.

Looking around the web

2条回答
  •  无人共我
    2021-02-10 11:05

    A Timer is a one-shot event. It cannot be made to loop this way.

    Using a Timer to call a function which then creates another Timer which calls a function that creates a Timer which calls a function which creates a Timer, ..., must reach the recursion limit.

    You don't mention your OS, but the "skipping" or "ticking irregularly" is for two reasons.

    1. You computer is busy and "1 second" means "pretty close to 1 second, depending on what else is going on"

    2. If you start your timer at 0.9999 seconds, and wait 1 second, you might be at 1.9999 (rounds down to 1) or 2.00000. It may appear to duplicate a time or skip a time. Your computer's internal hardware clock is very accurate, and rounding things off to the nearest second will (always) lead to the remote possibility of duplicates or skips.

    Use sched correctly. http://docs.python.org/library/sched.html#module-sched

    Your code snippet makes no sense for sched, either. You do not need to create a new scheduler object. You only need to create a new event.

    Read http://docs.python.org/library/sched.html#sched.scheduler.enter on creating a new event for an existing scheduler instance.

提交回复
热议问题