{ "info": { "author": "Mark Blakeney", "author_email": "mark@irsaere.net", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3" ], "description": "## TIMESCHED\n\nThe `timesched` Python module provides a simple time event scheduler. It\nis implemented upon the standard Python\n[`sched`](https://docs.python.org/3/library/sched.html) module and is\nused in a similar way, but provides a nicer and more modern and\nconvenient programming interface. Apart from normal oneshot and repeat\ntimers, it can run timers at a given time of day, and for the given days\nof week, providing simple cron-like functionality. It requires only\nPython 3.4 or later, and the standard library. The latest version of\nthis document and code is available at\nhttps://github.com/bulletmark/timesched.\n\n```python\nclass timesched.Scheduler(timefunc=time.time, delayfunc=time.sleep)\n```\n\nRefer to the class description for Python\n[sched.scheduler](https://docs.python.org/3/library/sched.html#sched.scheduler)\nwhich is used in the [internal\nimplementation](#differences-to-standard-sched-module) of this class.\n\n_Scheduler_ instances have the following methods.\n\n#### Create one-shot timer\n\n```python\noneshot(time, priority, func, *args, **kwargs)\n```\n- _time_: expiry time relative to now, or absolute time. Type can be one of:\n - `int` at given relative seconds after now,\n - `datetime.timedelta()` at given relative `timedelta()` after now,\n - `datetime.time()` at given `time()` after now,\n - `datetime.datetime()` at given absolute `datetime()`,\n - `datetime.date()` at given absolute `date()`,\n- _priority_: int value, lower value is higher priority. Refer\n [description](https://docs.python.org/3/library/sched.html#sched.scheduler.enterabs).\n- _func_ and _args_ and _kwargs_: user function and arguments to call\n when timer is invoked.\n\nReturns a _timer_ ID which can be used to cancel the timer using\n[`cancel(timer)`](#cancel-timer).\n\n#### Create repeating timer\n\n```python\nrepeat(period, priority, func, *args, **kwargs)\n```\n- _period_: period for timer. Type can be one of:\n - `int` at each given seconds after now,\n - `datetime.timedelta()` at each given `timedelta()` after now,\n - `datetime.time()` at given `time()` each day after now. E.g. at\n 10:30 every day for simple daily \"cron-like\" functionality.\n- _priority_: int value, lower value is higher priority. Refer\n [description](https://docs.python.org/3/library/sched.html#sched.scheduler.enterabs).\n- _func_ and _args_ and _kwargs_: user function and arguments to call\n when timer is invoked.\n\nReturns a _timer_ ID which can be used to cancel the timer using\n[`cancel(timer)`](#cancel-timer).\n\nNote that for _int_ and _timedelta()_ periods, the specified period is\nthe delay between the end of the callback function and when it is called\nagain so the actual period will slowly \"creep\" by the run time of the\ncallback. Many applications are not concerned about this distinction but if\nnecessary you can instead invoke a _oneshot()_ absolute timer between\neach call.\n\n#### Create one-shot timer on next given day\n\nCall this with _time_ = `datetime.time()` to invoke a `oneshot()` at the\ngiven _time_ on the next day from the set of given _days_ of the week.\n\n```python\noneshot_on_days(days, time, priority, func, *args, **kwargs)\n```\n\n- _days_: A list/sequence/range of integers 0-6 where 0 = Monday to 6 =\n Sunday. e.g. [0] means only invoke timer on a Monday, [0,6] = only\n invoke on Monday and Sunday, etc. Using `days=range(7)` is same as\n calling ordinary `oneshot()`.\n\n Alternately, you can specify _days_ as a string \"MTWTFSS\" where each\n char is upper case if the day is to be set, and lower case if not.\n E.g. \"MTWTFss\" is the working week Mon-Fri, \"mtwTfss\" is Thu only,\n etc. A utility function to explicitly parse this string into a list of\n integers is available as `timesched.parse_days(string_arg)` if you\n need.\n\nRemaining parameters and return type are same as `oneshot()`.\n\n#### Create repeating timer on given days\n\nCall this with _time_ = `datetime.time()` to invoke a `repeat()` at the\ngiven _period_ on each of the given _days_ of the week.\n\n```python\nrepeat_on_days(days, period, priority, func, *args, **kwargs)\n```\n\n- _days_: parameter same as `oneshot_on_days()`.\n\nRemaining parameters and return type are same as `repeat()`.\n\n#### Return count of active timers\n\n```python\ncount()\n```\n\nReturns the count of timers currently active. A timer is considered\nactive while it is pending and until it's callback function has\ncompleted, unless it is explicitly cancelled.\n\n#### Cancel timer\n\n```python\ncancel(timer)\n```\n\nRemove the timer with `timer` ID. If the timer is not currently active,\nthis method will raise a ValueError.\n\n#### Run scheduler\n\n```python\nrun(blocking=True)\n```\n\nInvokes the base `scheduler.run()`. Refer full\ndescription at [Python sched\nmodule](https://docs.python.org/3/library/sched.html#sched.scheduler.run).\n\n## EXAMPLES\n\n```python\n#!/usr/bin/python3\n'Example code and small test suite.'\nfrom datetime import datetime, timedelta\nimport timesched\n\n# Create a scheduler\ns = timesched.Scheduler()\n\ndef callback(typ, arg):\n print('{} {} {}, active={}'.format(str(datetime.now())[:19], typ,\n arg, s.count()))\n\nnow = datetime.now()\ncallback('started', 'now')\n\n# Set one shot timer to run 10 secs from now, passing int value\nsecs = 10\ns.oneshot(secs, 0, callback, 'oneshot', secs)\n\n# Set one shot timer to run 1 min from now, passing timedelta() value\nminute = timedelta(minutes=1)\ns.oneshot(minute, 0, callback, 'oneshot', minute)\n\n# Set one shot timer to run at absolute time, passing datetime() value\nnextmin = now + minute\ns.oneshot(nextmin, 0, callback, 'oneshot', nextmin)\n\n# Set one shot timer to run at absolute time today, passing time() value\nnexttime = nextmin.time()\ns.oneshot(nexttime, 0, callback, 'oneshot', nexttime)\n\n# Set repeat timer to run every 10 secs, passing int value\ns.repeat(secs, 0, callback, 'repeat', secs)\n\n# Set repeat timer to run every 1 min, passing timedelta() value\ns.repeat(minute, 0, callback, 'repeat', minute)\n\n# Set repeat timer to run every day at given time, passing time() value\ns.repeat(nexttime, 0, callback, 'repeat', nexttime)\n\n# Set repeat timer to run every weekday at given time, passing time() value\ns.repeat_on_days([nextmin.weekday()], nexttime, 0, callback,\n 'repeat_on_days', nexttime)\n# Same this but run every day and use string for day of week\ns.repeat_on_days('MTWTFSS', nexttime, 0, callback, 'repeat_on_days', nexttime)\n\n# Create and then immediately cancel a couple of timers before they\n# execute.\ntimer1 = s.oneshot(secs, 0, callback, 'oneshot', 'cancel')\ntimer2 = s.repeat(secs, 0, callback, 'repeat', 'cancel')\ns.cancel(timer1)\ns.cancel(timer2)\n\n# Run scheduler, will block until no timers left running\ns.run()\n```\n\n## DIFFERENCES TO STANDARD SCHED MODULE\n\nThe `timesched` module is internally implemented using the standard\nPython [`sched`](https://docs.python.org/3/library/sched.html) module\nbut differs in the following ways. Note that the `sched` implementation,\nmethods, and attributes are not directly exposed in the public interface.\n\n- Provides `oneshot()` and `repeat()` methods to conveniently accept\n standard\n [`datetime.datetime()`](https://docs.python.org/3/library/datetime.html#datetime-objects),\n [`datetime.date()`](https://docs.python.org/3/library/datetime.html#date-objects),\n [`datetime.time()`](https://docs.python.org/3/library/datetime.html#time-objects),\n [`datetime.timedelta()`](https://docs.python.org/3/library/datetime.html#timedelta-objects),\n and also integer time arguments, based automatically on the type of the\n passed time argument.\n- The `repeat()` method sets itself up to be automatically invoked again\n at the next repeat interval, unlike `sched` which only provides a\n `oneshot()` equivalent method [i.e. `enter()` or `enterabs()`] so the user\n does not need to explicitly set up the next timer.\n- Provides a convenient way to schedule a timer at a given time each\n day to give simple daily \"cron-like\" functionality, e.g.\n `s.repeat(datetime.time(hour=10, minute=30), f)` to periodically\n activate a timer at 10:30 every day.\n- Further to the above `repeat()` which can run at a given time every\n day, you can use `repeat_on_days()` to specify a given time on a set\n of given days, e.g. `s.repeat_on_days('MTWTFss',\n datetime.time(hour=10, minute=30), f)` to run the timer at 10:30 each\n workday only (Mon to Fri). Alternately `s.repeat_on_days(range(5),\n datetime.time(hour=10, minute=30), f)`\n gives the same result.\n- Consistent with modern Python, allows user to plainly specify `*args`\n and `**kwargs` directly in timer setup call rather than in a tuple as\n legacy `sched` requires.\n- Does not provide the\n [`enter()`](https://docs.python.org/3/library/sched.html#sched.scheduler.enter)\n or\n [`enterabs()`](https://docs.python.org/3/library/sched.html#sched.scheduler.enterabs)\n methods. Use the superior `oneshot()`, `repeat()`,\n `oneshot_on_days()`, or `repeat_on_days()` methods instead.\n- Provides a more specific `count()` method instead of\n [`empty()`](https://docs.python.org/3/library/sched.html#sched.scheduler.empty).\n- Does not provide the\n [`queue`](https://docs.python.org/3/library/sched.html#sched.scheduler.queue)\n attribute.\n- Uses `time.time` instead of `time.monotonic` as the default `timefunc`\n for the internal\n [scheduler](https://docs.python.org/3/library/sched.html#sched.scheduler).\n This is to be compatible with\n [`datetime.datetime.timestamp()`](https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp) which is used internally.\n\n## INSTALLATION\n\nArch Linux users can install [timesched from the\nAUR](https://aur.archlinux.org/packages/timesched/).\n\n`timesched` is [available on PyPI](https://pypi.org/project/timesched/)\nso install the usual way, e.g:\n\n```bash\npip install timesched\n```\n\nOr explicitly from [github](https://github.com/bulletmark/timesched):\n\n```bash\ngit clone https://github.com/bulletmark/timesched.git\ncd timesched\nsudo make install\n```\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/bulletmark/timesched", "keywords": "sched scheduler timer periodic cron crontab", "license": "GPLv3", "maintainer": "", "maintainer_email": "", "name": "timesched", "package_url": "https://pypi.org/project/timesched/", "platform": "", "project_url": "https://pypi.org/project/timesched/", "project_urls": { "Homepage": "https://github.com/bulletmark/timesched" }, "release_url": "https://pypi.org/project/timesched/1.3/", "requires_dist": null, "requires_python": ">=3.4", "summary": "Improved simple time scheduler based on standard sched", "version": "1.3" }, "last_serial": 4679093, "releases": { "1.3": [ { "comment_text": "", "digests": { "md5": "a1fcd64a93b97a9d5311df4701d8b052", "sha256": "c0a4942a9b6ab7df4d4d46362ac3fbb88c92d3e0135c1c8263b9950b4ed70e07" }, "downloads": -1, "filename": "timesched-1.3.tar.gz", "has_sig": false, "md5_digest": "a1fcd64a93b97a9d5311df4701d8b052", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 6532, "upload_time": "2019-01-10T00:59:34", "url": "https://files.pythonhosted.org/packages/39/57/fcc782e45d23ac38c2f6a38ede7f0e4bc0d6fe73cb8de2a88e1a62073641/timesched-1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a1fcd64a93b97a9d5311df4701d8b052", "sha256": "c0a4942a9b6ab7df4d4d46362ac3fbb88c92d3e0135c1c8263b9950b4ed70e07" }, "downloads": -1, "filename": "timesched-1.3.tar.gz", "has_sig": false, "md5_digest": "a1fcd64a93b97a9d5311df4701d8b052", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 6532, "upload_time": "2019-01-10T00:59:34", "url": "https://files.pythonhosted.org/packages/39/57/fcc782e45d23ac38c2f6a38ede7f0e4bc0d6fe73cb8de2a88e1a62073641/timesched-1.3.tar.gz" } ] }