Extend `schedule` to work as a decorator
See original GitHub issueI would love to see schedule
extended to work as a decorator. I envision syntax along the lines of
@schedule.every().hour.do
def job():
print("I'm working...")
However, this doesn’t work.
When thinking through this, I found that this does work now:
import schedule
import time
dec = schedule.every(2).seconds.do
@dec
def job():
print("I'm working...")
Parentheses aren’t allowed in decorators. (I think this is a result of Guido’s gut feeling.) Syntax along the lines of this would be permitted: @schedule.every.seconds.do
.
Maybe it’d be insane, but we could implement something like @schedule.every.ten.seconds.do
. There’s probably a clever way to make that work for a large number of cases. Though, it doesn’t resolve the issue of hard coding times.
Some discussion would be helpful before anyone tries implementing this.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Primer on Python Decorators
In this introductory tutorial, we'll look at what Python decorators are and how to create and use them.
Read more >12 Best Time Management Tips for Interior Designers - Foyr Neo
Time is crucial in completing interior design projects, taking up new work, scheduling, planning and executing work. But it's easier said than done....
Read more >10 Time Management Tips To Help Interior Designers Work ...
8. Manage Your Calendar ... A big part of your job as an interior designer is to work with other people's schedules. It...
Read more >How To Optimize Shift Work Scheduling To Maximize ...
Shift scheduling tip #5: Ask for employee input. Despite your best efforts, some workers may never adjust to certain shifts, especially ...
Read more >Extending @property.setter decorator in Python - Stack Overflow
I still would like to extend property (or implement my own version, but I'm not sure through which mechanism it works, it's different...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This comes for free with CPython 3.9.
https://www.python.org/dev/peps/pep-0614/
Dear future visitor,
There is now a decorator for this. See #148.