Skip to content

Commit fdb0977

Browse files
Yi ZhangYi Zhang
authored andcommitted
fix bugs
1 parent ce0d063 commit fdb0977

3 files changed

Lines changed: 68 additions & 8 deletions

File tree

README.md

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ Create a TimerThread scheduler and start it:
3333
```python
3434
import 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

4040
Shutdown 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

6565
When 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

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setuptools.setup(
1010
name='TimerThread',
11-
version='0.1.0',
11+
version='0.1.1',
1212
description='A lightweight task scheduling timer',
1313
author='Yi Zhang',
1414
author_email='yizhang.dev@gmail.com',
@@ -20,6 +20,7 @@
2020
'timerthread'
2121
],
2222
keywords=[
23+
'timer',
2324
'background-jobs',
2425
'background-thread',
2526
'tasks',

timerthread/scheduler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
TIMEFORMAT = '%Y-%m-%d %H:%M:%S %Z'
55

66
import threading
7+
import time
78

89

910
class Scheduler(threading.Thread):

0 commit comments

Comments
 (0)