dbader / dbader/schedule

Event Loop based run_pending coroutine

Open
#325 2 comments 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 needed to read the return value from several of my scheduled tasks so i made a custom scheduler which does work in event loop fashion:
```python
import schedule

class CustomScheduler(schedule.Scheduler):
def __init__(self):
super().__init__()

def _check_runnable(self):
return tuple((job for job in self.jobs if job.should_run))

def start_run_pending(self):
r = self._enhanced_run_pending()
next(r)
return lambda x: r.send(x)

def _enhanced_run_pending(self):
while True:
jobs = (yield)
if isinstance(jobs, schedule.CancelJob):
return jobs

yield (self.__run_job(job) for job in jobs)

def __run_job(self, job):
ret = job.run()
if isinstance(ret, schedule.CancelJob) or ret is schedule.CancelJob:
self.cancel_job(job)
else:
return ret
```

Usage example:

```python
while True:
runnables = self.job_schedule._check_runnable()
runner = self.job_schedule._enhanced_run_pending()
job_res = runner(runnables)
ret_val= tuple(job_res)
time.sleep(1)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading schedule.Scheduler, run_pending, and Job.run, along with the existing job cancellation behavior. Compare the proposed event-loop flow with the scheduler’s current execution model and determine how returned task values should be exposed. Done should include a supported event-loop-based runner that returns job results while preserving CancelJob handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.