question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extend `schedule` to work as a decorator

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
medecaucommented, Oct 29, 2020

This comes for free with CPython 3.9.

https://www.python.org/dev/peps/pep-0614/

0reactions
medecaucommented, Feb 4, 2021

Dear future visitor,

There is now a decorator for this. See #148.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found