Skip to main content

Requirements

  • Python – one of the following:

Installation

Package is uploaded on PyPI.

You can install it with pip:

$ python3 -m pip install simple_watchdog_timer

Backwards compatibility

Backwards compatibility is only guaranteed between minor versions above the stable version (1.0) Therefore it’s advised to to pin the module on a version ether the specific version like: simple_watchdog_timer==X.X.X

or get the latest minor version: simple_watchdog_timer~=X.X.X

See more examples of how to pin version in PEP-440.

Documentation

For support, please refer to StackOverflow.

Example

The following example showcases the usage

from simple_watchdog_timer.simple_watchdog_timer import WDT
from random import uniform
from time import sleep


def cb(dog):
    # When the callback gets triggered, it's good practice to pause the WDT to prevent it firing again, while you are handling the action required when it triggers
    dog.pause()

    # Do something when the WDT triggers...
    print('WDT Triggered')

    # Update / reset the internal WDT timer (dog.reset() does the same), this is important to avoid the time spent in the callback to influence the next triggering
    dog.update()

    # Resume the WDT
    dog.resume()

    # ...or:

    # If you would like to completely stop the WDT
    # dog.stop()

    # But you regret and want to start it again
    # dog.start()

    # Tip: stop() and start() can also be used instead of the more manual pause, update and resume if that is preferred (more simple, but less in-line expressive)


def main():
    wdt = WDT(check_interval_sec=0.01, trigger_delta_sec=0.50, callback=cb)

    while True:
        zzz_sec = uniform(0, 0.60)
        print('Sleep for {}'.format(zzz_sec))
        sleep(zzz_sec)

        wdt.update()


if __name__ == '__main__':
    main()

This example will print:

Raw data:
Sleep for 0.1492276414753453
Sleep for 0.5913061085397784
WDT Triggered
Sleep for 0.17619615161373772
Sleep for 0.5853218597734956
WDT Triggered
Sleep for 0.38154937243934783
Sleep for 0.5000195244886919
WDT Triggered
Sleep for 0.08607711764377268
Sleep for 0.31192761174090605
Sleep for 0.02722456895623042

License

TimedDict is released under the MIT License. See LICENSE for more information.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_watchdog_timer-0.1.0.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file simple_watchdog_timer-0.1.0.tar.gz.

File metadata

  • Download URL: simple_watchdog_timer-0.1.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.3

File hashes

Hashes for simple_watchdog_timer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ee43dc8ffb3db75bfde70ad32450ecde3f74d2e103e6edb502245db90c7df8fe
MD5 1305b5a2fc09cc06a7b9b29cc472bf14
BLAKE2b-256 ceaea3fcabf0d13ab2163d258607d862f2a59eb82b6fc2df3614e33864467910

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

1 file

This release

0.1.0 This release

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page