@@ -33,14 +33,14 @@ Create a TimerThread scheduler and start it:
3333``` python
3434import timerthread
3535
36- task = timerthread.Scheduler(' recur' , 3 , now, args = (1 ,))
37- task .start()
36+ timer = timerthread.Scheduler(' recur' , 3 , now, args = (1 ,))
37+ timer .start()
3838```
3939
4040Shutdown the scheduler:
4141
4242``` python
43- task .cancel()
43+ timer .cancel()
4444```
4545
4646
@@ -58,19 +58,77 @@ def now(cost=1):
5858 time.sleep(cost)
5959 print ( time.strftime(' %Y-%m-%d %H:%M:%S %Z' , time.localtime()) )
6060
61- task = now.sched(cost = 1 )
62- task .start()
61+ timer = now.sched(cost = 1 )
62+ timer .start()
6363```
6464
6565When you'd like to cancel the recurring execution, shutdown the scheduler as usual:
6666
6767``` python
68- task .cancel()
68+ timer .cancel()
6969```
7070
7171
7272
73+ ### Install TimerThread
74+
75+ ``` bash
76+ $ pip install timerthread
77+ ```
78+
79+
80+
81+ ## Documentation
82+
83+ ### ` Scheduler `
84+
85+ ``` python
86+ class timerthread.Scheduler(trigger, interval, fn, args = (), kwargs = {})
87+ ```
88+
89+ ` trigger ` must be ` 'delay' ` or ` 'recur' ` .
90+
91+ * ` stopped `
92+
93+ The scheduler is stopped or not, ` True ` (default) or ` False ` .
94+
95+ * ` result `
96+
97+ The execution result, ` {} ` as default.
98+
99+ * ` start() `
100+
101+ Let scheduler start executing your function as scheduled in the background.
102+
103+ * ` cancel() `
104+
105+ Shutdown the scheduler.
106+
107+
108+
109+ ### ` task `
110+
111+ ``` python
112+ class timerthread.task(trigger, interval)
113+ ```
114+
115+ ` trigger ` must be ` 'delay' ` or ` 'recur' ` .
116+
117+ * Use ` @task ` decorator to define your function, then schedule it and start the scheduler:
118+
119+ ``` python
120+ @timerthread.task (trigger, interval)
121+ def fn (args , kwargs ):
122+ pass
123+
124+ timer = fn.sched(* args, ** kwargs)
125+ ```
126+
127+ ` fn.sched(*args, **kwargs) ` returns ` timerthread.Scheduler ` instance.
128+
129+
130+
73131## Related Projects
74132
75- * [ threading.Timer] ( https://github.com/python/cpython/blob/3.7/Lib/threading.py#L1153 ) ([ Timer Objects] ( https://docs.python.org/3.7/library/threading.html?highlight=thread#timer-objects ) )
133+ * [ ` threading.Timer ` ] ( https://github.com/python/cpython/blob/3.7/Lib/threading.py#L1153 ) ([ Timer Objects] ( https://docs.python.org/3.7/library/threading.html?highlight=thread#timer-objects ) )
76134
0 commit comments