我目前正在扩展我正在努力的项目,今天是我第一次有工作节点尝试与我的MySQL数据库通信异步时尚。详细说来,在开发这个项目时,我一直在使用Celery(http://www.celeryproject.org/)在具有单核的本地VM上,因此一次只运行一个工作进程。既然我已经增加了我的并发工作者数量,那么数据库连接器就会死亡(并且很痛苦)。我看到的其中一个错误的示例输出如下所示:
[2015-11-18 17:21:40,457: DEBUG/Worker-4] Task runner of class SeedPreparationTaskRunner initialized with Task ID 6.
[2015-11-18 17:21:40,458: INFO/Worker-4] Now running task runner for Task 6.
[2015-11-18 17:21:40,475: DEBUG/Worker-5] Task runner of class SeedPreparationTaskRunner initialized with Task ID 7.
[2015-11-18 17:21:40,480: INFO/Worker-5] Now running task runner for Task 7.
[2015-11-18 17:21:40,481: ERROR/Worker-4] Exception raised during execution of Task 6. Exception was This result object does not return rows. It has been closed automatically.. S
tack trace was Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/usr/lib/websight/tasknode/celery/celerytasks.py", line 21, in run_task_with_id
TaskManager.run_task(task_id=task_id)
据我所知,问题是这行代码在两个独立的进程中几乎完全同时运行:
with session_scope() as session:
task = Task.by_id(session, self.task_id)
by_id方法如下所示:
@classmethod
def by_id(cls, session, input_id):
return session.query(cls).filter_by(id=input_id).first()
我对数据库API /连接器的工作方式不太了解,但我猜我正在使用的MySQL数据库连接器并不像多个进程同时尝试通过它发出查询
所以,话虽如此,我想知道以下内容:
谢谢大家!