Skip to content

Commit 7674930

Browse files
committed
cron: move to main thread
1 parent 3077791 commit 7674930

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

anon/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 通用数据结构
2-
VERSION = '0.2.1'
2+
VERSION = '0.2.2'
33

44

55
class AnonError(Exception):

anon/plugin.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import threading
32
from typing import List, Type
43

54
import aiocron
@@ -9,14 +8,13 @@
98
from .logger import logger
109

1110

12-
class CronThread(threading.Thread):
11+
class CronThread:
1312
loop: asyncio.AbstractEventLoop
1413
tasks = set()
1514

1615
def __init__(self, loop):
1716
super().__init__()
1817
self.loop = loop
19-
self.start()
2018

2119
def add_cron(self, cron: str, func, *args):
2220
async def wrapper():
@@ -26,10 +24,6 @@ async def wrapper():
2624
task = aiocron.crontab(cron, func=wrapper, loop=self.loop)
2725
self.tasks.add(task)
2826

29-
def stop(self):
30-
logger.warn('CronThread stopping...')
31-
self.loop.call_soon_threadsafe(self.loop.stop)
32-
3327

3428
class Plugin:
3529
interested: List[Type[Event]]
@@ -105,7 +99,6 @@ def broad_cast(self, event: Event):
10599

106100
async def shutdown(self, timeout: int):
107101
logger.info(f'Plugins shutting down, timeout = {timeout}s...')
108-
self._cron.stop()
109102
for plugin in self.plugins:
110103
await self._loop.create_task(plugin.on_shutdown())
111104
for i in range(timeout):

0 commit comments

Comments
 (0)