You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered a rather peculiar issue where setting a smaller time interval for Apscheduler tasks resulted in the "Not connected" problem during asynchronous execution of MySQL writes.
I modified a convenient-to-use base class for Apscheduler myself.
Utilizing this base class, I have written a scheduled task.
classMyTask(BaseTask):
redis_client=global_om["redis_client"]
def__init__(self):
super().__init__()
self.job_config.update(
{
"trigger": CronTrigger(second="*/5"),
"max_instances": 1,
}
)
asyncdefjob_func(self):
logger.debug("Running mytask")
try:
all_objs=awaitObjClass.all()
exceptExceptionasexc:
logger.error(f"Mytask error - {exc.__class__.__name__}:{exc}")
# ... Some additional logic code for handling reading and writing to Redisasyncio.create_task(self._delete_obj(all_objs))
asyncdef_delete_obj(self, all_objs):
# ... Some additional logic code for handling reading and writing to Redisnew_objs=awaitObjClass.filter(id__in=[obj.idforobj_inall_objs])
# ...awaitObjClass.filter(id__in=[obj.idforobj_inall_objs]).delete()
# ...
I am using the ORM framework Tortoise-ORM version 0.19.1, and I have defined an ObjClass. Currently, the task interval is set to 5 seconds. However, when I reduce the task interval to 2 seconds or any other value, after running the program for a while, I encounter a pymysql.InterfaceError(0, "Not connected"). This error consistently occurs at the line await ObjClass.filter(id__in=[obj.id for obj_ in all_objs]).delete(). The preceding query statement is always successful, and once this error occurs, it cannot be recovered from.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I encountered a rather peculiar issue where setting a smaller time interval for Apscheduler tasks resulted in the "Not connected" problem during asynchronous execution of MySQL writes.
I modified a convenient-to-use base class for Apscheduler myself.
Utilizing this base class, I have written a scheduled task.
I am using the ORM framework Tortoise-ORM version 0.19.1, and I have defined an
ObjClass
. Currently, the task interval is set to 5 seconds. However, when I reduce the task interval to 2 seconds or any other value, after running the program for a while, I encounter apymysql.InterfaceError(0, "Not connected")
. This error consistently occurs at the lineawait ObjClass.filter(id__in=[obj.id for obj_ in all_objs]).delete()
. The preceding query statement is always successful, and once this error occurs, it cannot be recovered from.Beta Was this translation helpful? Give feedback.
All reactions