简体   繁体   中英

OperationalError: disk I/O error when using Process

I'm running a django app which uses sqlite3 as backend. I have a function which does a db write operation. Something like the one given below.

def task_run():
    db_write()

This works fine in normal case. I called the same function in Process module and it thrown 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

Any idea why this happens? How can i call the same function using multiprocessing?

I also meet this wield error today, perhaps you can use memory to detour it. Like this below:

con = sqlite3.connect(":memory:")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM