agronholm / agronholm/apscheduler
The schedule cannot be removed in event handler
- Ngôn ngữ chính
- Python
- Star
- 7.6k
- Fork
- 783
- Merge trung bình
- 4 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 5
Mô tả
### Things to check first
- [x] I have checked that my issue does not already have a solution in the [FAQ](https://apscheduler.readthedocs.io/en/master/faq.html)
- [x] I have searched the existing issues and didn't find my bug already reported there
- [x] I have checked that my bug is still present in the latest release
### Version
4.0.0a6
### What happened?
In the event handler when I process the JobReleased event, I try to remove the schedule.
And this causes an error
### How can we reproduce the bug?
##### Code:
```python
import asyncio
from apscheduler import AsyncScheduler, JobReleased, current_async_scheduler
from apscheduler.triggers.interval import IntervalTrigger
async def task():
pass
async def event_handler(event):
scheduler = current_async_scheduler.get()
await scheduler.remove_schedule('schedule_id')
async def main():
async with AsyncScheduler() as scheduler:
scheduler.subscribe(event_handler, JobReleased)
await scheduler.add_schedule(
task,
IntervalTrigger(seconds=10),
id='schedule_id'
)
await scheduler.run_until_stopped()
if __name__ == '__main__':
asyncio.run(main())
```
##### Error:
```python
Scheduler crashed
+ Exception Group Traceback (most recent call last):
| File "/python3.11/site-packages/apscheduler/_schedulers/async_.py", line 876, in run_until_stopped
| async with create_task_group() as task_group:
| File "/python3.11/site-packages/anyio/_backends/_asyncio.py", line 772, in __aexit__
| raise BaseExceptionGroup(
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "/python3.11/site-packages/apscheduler/_schedulers/async_.py", line 1070, in _process_schedules
| await self.data_store.release_schedules(self.identity, results)
| File "/python3.11/site-packages/apscheduler/datastores/memory.py", line 181, in release_schedules
| schedule = self._schedules_by_id[result.schedule_id]
| ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
| KeyError: 'schedule_id'
```
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.