0

I am attempting a simple script that schedules a set of commands. I want to build, but I am stuck with the initial steps using the sched2 package

What I ultimately trying to do is to have a set of commands that will execute at a set of time delays. My failing attempt below:

from time import time
from datetime import datetime, timedelta
from sched2 import scheduler

sc = scheduler()
@sc.enter(delay=timedelta(minutes=1), priority=0)
print("this is a test at 1 min)

@sc.every(delay=timedelta(minutes=1.5), priority=0)
print("this is a test at 1.5 min")

sc.run()

Any assistant is appreciated.

1 Answer 1

1

I don't have any experience with the sched2 library, but Python decorators are used to decorate functions, not just lines of code. Try wrapping your print statements inside a function.

from time import time
from datetime import datetime, timedelta
from sched2 import scheduler

sc = scheduler()

@sc.enter(delay=timedelta(minutes=1), priority=0)
def one_minute():
    print("this is a test at 1 min)

@sc.every(delay=timedelta(minutes=1.5), priority=0)
def one_and_half_minute():
    print("this is a test at 1.5 min")

sc.run()

This is what it looks like they are doing in the docs https://pypi.org/project/sched2/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.