我正在运行一个使用sqlite3作为后端的django应用程序。我有一个执行db写操作的函数。像下面给出的东西。
def task_run():
db_write()
这在正常情况下工作正常。我在Process模块中调用了相同的函数,并抛出OperationalError: disk I/O error
p = Process(target=self.task_run, args=())
p.start()
p.join()
Error:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "...runner.py", line 277, in task_runner
getattr(main, "first_function")("some random")
File "...modules/test/main.py", line 13, in first_function
self.__event__('information',"Testing plugin profiles")
File "...rc_plugin.py", line 28, in __event__
event = Event.objects.post_event(self.job_id, self.task_id, type, message)
File "...managers.py", line 39, in post_event
if len(dup_events)>0:
File "...lib/python2.7/site-packages/django/db/models/query.py", line 144, in __len__
self._fetch_all()
File "...lib/python2.7/site-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "...lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
results = compiler.execute_sql()
File "...lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
cursor.execute(sql, params)
File "...lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "...lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "...lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "...lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "...lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 318, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: disk I/O error
知道为什么会这样吗?如何使用多处理调用相同的函数?
答案 0 :(得分:0)
我今天也遇到了这个错误的错误,也许你可以用内存来绕道它。如下所示:
con = sqlite3.connect(":memory:")