timeloop


Nametimeloop JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/sankalpjonn/timeloop
SummaryAn elegant way to run period tasks.
upload_time2019-02-12 12:06:15
maintainer
docs_urlNone
authorSankalp Jonna
requires_python
licenseMIT
keywords tasks jobs periodic task interval periodic job flask style decorator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Timeloop
Timeloop is a service that can be used to run periodic tasks after a certain interval.

![timeloop](http://66.42.57.109/timeloop.jpg)

Each job runs on a separate thread and when the service is shut down, it waits till all tasks currently being executed are completed.

Inspired by this blog [`here`](https://www.g-loaded.eu/2016/11/24/how-to-terminate-running-python-threads-using-signals/)

## Installation
```sh
pip install timeloop
```

## Writing jobs
```python
import time

from timeloop import Timeloop
from datetime import timedelta

tl = Timeloop()

@tl.job(interval=timedelta(seconds=2))
def sample_job_every_2s():
    print "2s job current time : {}".format(time.ctime())

@tl.job(interval=timedelta(seconds=5))
def sample_job_every_5s():
    print "5s job current time : {}".format(time.ctime())


@tl.job(interval=timedelta(seconds=10))
def sample_job_every_10s():
    print "10s job current time : {}".format(time.ctime())
```

## Start time loop in separate thread
By default timeloop starts in a separate thread.

Please do not forget to call ```tl.stop``` before exiting the program, Or else the jobs wont shut down gracefully.

```python
tl.start()

while True:
  try:
    time.sleep(1)
  except KeyboardInterrupt:
    tl.stop()
    break
```

## Start time loop in main thread
Doing this will automatically shut down the jobs gracefully when the program is killed, so no need to  call ```tl.stop```
```python
tl.start(block=True)
```

## Author
* **Sankalp Jonna**

Email me with any queries: [sankalpjonna@gmail.com](sankalpjonna@gmail.com).



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sankalpjonn/timeloop",
    "name": "timeloop",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "tasks,jobs,periodic task,interval,periodic job,flask style,decorator",
    "author": "Sankalp Jonna",
    "author_email": "sankalpjonna@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6a/95/3e39ee32f15a8e9dea46bb52300611a5351964eeaa393bafb0d738e90ce0/timeloop-1.0.2.tar.gz",
    "platform": "",
    "description": "# Timeloop\nTimeloop is a service that can be used to run periodic tasks after a certain interval.\n\n![timeloop](http://66.42.57.109/timeloop.jpg)\n\nEach job runs on a separate thread and when the service is shut down, it waits till all tasks currently being executed are completed.\n\nInspired by this blog [`here`](https://www.g-loaded.eu/2016/11/24/how-to-terminate-running-python-threads-using-signals/)\n\n## Installation\n```sh\npip install timeloop\n```\n\n## Writing jobs\n```python\nimport time\n\nfrom timeloop import Timeloop\nfrom datetime import timedelta\n\ntl = Timeloop()\n\n@tl.job(interval=timedelta(seconds=2))\ndef sample_job_every_2s():\n    print \"2s job current time : {}\".format(time.ctime())\n\n@tl.job(interval=timedelta(seconds=5))\ndef sample_job_every_5s():\n    print \"5s job current time : {}\".format(time.ctime())\n\n\n@tl.job(interval=timedelta(seconds=10))\ndef sample_job_every_10s():\n    print \"10s job current time : {}\".format(time.ctime())\n```\n\n## Start time loop in separate thread\nBy default timeloop starts in a separate thread.\n\nPlease do not forget to call ```tl.stop``` before exiting the program, Or else the jobs wont shut down gracefully.\n\n```python\ntl.start()\n\nwhile True:\n  try:\n    time.sleep(1)\n  except KeyboardInterrupt:\n    tl.stop()\n    break\n```\n\n## Start time loop in main thread\nDoing this will automatically shut down the jobs gracefully when the program is killed, so no need to  call ```tl.stop```\n```python\ntl.start(block=True)\n```\n\n## Author\n* **Sankalp Jonna**\n\nEmail me with any queries: [sankalpjonna@gmail.com](sankalpjonna@gmail.com).\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An elegant way to run period tasks.",
    "version": "1.0.2",
    "project_urls": {
        "Homepage": "https://github.com/sankalpjonn/timeloop"
    },
    "split_keywords": [
        "tasks",
        "jobs",
        "periodic task",
        "interval",
        "periodic job",
        "flask style",
        "decorator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ade7371d64fc6c6fce53c490fc38816a77fe8c75ff608edc0807170ff3c62bf2",
                "md5": "a588891654e05ba9b8018dfc9b4d170f",
                "sha256": "70cb69eeef39968ea0e6dd68a3a3a51257d5f4aa27b177ab1b19ca86ff525946"
            },
            "downloads": -1,
            "filename": "timeloop-1.0.2-py2-none-any.whl",
            "has_sig": false,
            "md5_digest": "a588891654e05ba9b8018dfc9b4d170f",
            "packagetype": "bdist_wheel",
            "python_version": "py2",
            "requires_python": null,
            "size": 5220,
            "upload_time": "2019-02-12T12:06:14",
            "upload_time_iso_8601": "2019-02-12T12:06:14.014148Z",
            "url": "https://files.pythonhosted.org/packages/ad/e7/371d64fc6c6fce53c490fc38816a77fe8c75ff608edc0807170ff3c62bf2/timeloop-1.0.2-py2-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6a953e39ee32f15a8e9dea46bb52300611a5351964eeaa393bafb0d738e90ce0",
                "md5": "791704da1f2e0494aa79229d999fd8cb",
                "sha256": "4e716c67fe6bcadcee7ddb91e2520792426818a70f27e630cfbbbd9becc48a13"
            },
            "downloads": -1,
            "filename": "timeloop-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "791704da1f2e0494aa79229d999fd8cb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 2902,
            "upload_time": "2019-02-12T12:06:15",
            "upload_time_iso_8601": "2019-02-12T12:06:15.779292Z",
            "url": "https://files.pythonhosted.org/packages/6a/95/3e39ee32f15a8e9dea46bb52300611a5351964eeaa393bafb0d738e90ce0/timeloop-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-02-12 12:06:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sankalpjonn",
    "github_project": "timeloop",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "timeloop"
}
        
Elapsed time: 0.13960s