agronholm / agronholm/apscheduler

The schedule cannot be removed in event handler

オープン
#1,076 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
7.6k
フォーク
783
平均マージ
4日 8時間
マージ済み PR(30日)
5

説明

### 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'
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。