Example
#test.py
from pytasks import App
from datetime import datetime as dt
from datetime import timedelta as td
class T:
def __init__(self, taskid):
self.times = 10 #<--------------the largest number of this task will be executed
self.now = dt.now()
self.every = td(seconds=4) #<------frequency of task being polled
self.taskid = taskid
def __call__(self): #<--------------content of task
print self.taskid, ":", dt.now()-self.now
self.now =dt.now()
def schedule(self): #<--------------task'schedule:
return dt.now()+td(seconds=2) #return bool() or datetime.datetime(...)[means the time to run task]
task1 = T(1)
task2 = T(2)
#set task2's schedule
task2.schedule = lambda: True if os.environ['LOGNAME']=='root' else False
app = App()
app.add(task1)
app.add(task2
app.run()
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytasks-1.2.tar.gz
(4.9 kB
view details)
File details
Details for the file pytasks-1.2.tar.gz.
File metadata
- Download URL: pytasks-1.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1493636f6c8196a1524e929fd0cff67f3898709621c386a912b4a84099e86c6d
|
|
| MD5 |
7498edfed4bae45e1876f119f31447a7
|
|
| BLAKE2b-256 |
902c143f944ca8859d4de48e6cc53a0dedb562c024e3cb73fa72b87f227e568f
|