dbader / dbader/schedule

Wait the job ends before starts again

Open
#211 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
12.3k
Forks
999
PR merge metrics
No merged PRs in 30d

Description

I'm looking for a method to schedule a job to run every 2 seconds but without to start another thread while the first one is running yet.
I read the FAQ and the issues but no one comment about it.

```
import threading
import time
import schedule

def job():
print("A: %s" % threading.get_ident(), time.time())
time.sleep(3)
print("B: %s" % threading.get_ident(), time.time())

def run_threaded(job_func):
job_thread = threading.Thread(target=job_func)
job_thread.start()

schedule.every(2).seconds.do(run_threaded, job)

while 1:
schedule.run_pending()
time.sleep(1)
```

The output is:
```
A: 139822667417344 1524702860
A: 139822659024640 1524702862
B: 139822667417344 1524702863
A: 139822667417344 1524702864
B: 139822659024640 1524702865
A: 139822659024640 1524702866
B: 139822667417344 1524702867
A: 139822667417344 1524702868
```

But, I would like something like it:
```
A: 139822667417344 1524702860
B: 139822667417344 1524702863
A: 139822667417344 1524702865
B: 139822667417344 1524702868
```

The `every(2)` start to count after the job ends.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the supplied example and reading the behavior of schedule.every(...).seconds.do and schedule.run_pending. Use the requested output sequence as the acceptance criterion, including the case where a job runs longer than its interval and must not overlap with the next run.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.