Package: gevent-tasks
gevent-tasksBackground task manager using Gevent and Green threads.Check outthe documentation.Learn aboutGevent.This library is designed to allow a developer to run arbitrary "tasks" as background
threads on a fixed/normalized interval.  Each task is a wrapped
callable that takes at least one parametertask, a reference to itself. Timings
and related metadata can be accessed via thetaskvalue as well as the ability
to stop and reschedule itself for future events.TaskManagerhas aTaskPoolthat runsTasks.InstallationThe latest version from pypi,$pipinstallgevent-tasksThe latest development version from source,$pipinstallgit+git@github.com:blakev/gevent-tasks.git@developExamplesA classic example,# print our system uptime every minute, indefinitelyfromdatetimeimporttimedeltafromgevent_tasksimportTaskManager,cronmanage=TaskManager()@manage.task(interval=cron('* * * * *'))defsystem_uptime(task):withopen('/proc/uptime','r')asf:uptime_seconds=float(f.readline().split()[0])uptime=str(timedelta(seconds=uptime_seconds))print(uptime)manage.forever(stop_after_exc=False)Contrived example,fromgevent.monkeyimportpatch_allpatch_all()fromgevent_tasksimportTask,TaskManager,TaskPoolfrommyapp.tasksimportcheck_websockets,check_uptime,check_healthpool=TaskPool(size=25)manager=TaskManager(pool=pool)manager.add_many(Task('WebsocketHealth',check_websockets,interval=7.5),Task('ApplicationHealth',check_uptime,interval=30.0),Task('SystemHealth',check_health,args=('localhost',),interval=2.5))manager.start_all()....http_server.serve_forever()Using theparse-crontabmodule we're able to define intervals with cron syntax,fromgevent_tasksimportTask,cron....Task('ShowCharts',show_charts,interval=cron('* * * * *'),timeout=30.0)The manager instance can also be used to register tasks via decorator. CallingTaskManager.forever()will block the code until there are no longer scheduled tasks or until anExceptionis thrown inside one of the running Tasks.manage=TaskManager()@manage.task(interval=cron('* * * * *'))defevery_minute(task,*args):print('hi',args,task,task.timing)manage.forever()You can also reference the previous return value, allowing tasks to build on
themselves over time without human / programmatic interaction.@manage.task(interval=1)defrandom_number(task):num=random.randint(0,100)print(task.value,num)returnnum..output..None51515050888826AttributionThis module relies primarily on thegeventproject for all its core functionality.MIT LicenseCopyright (c) 2017 Blake VandeMerwePermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.