Closed albertz closed 11 years ago
I searched a bit around and here is probably the explanation:
SQLite does not allow the use of database connections across `forked
<http://en.wikipedia.org/wiki/Fork_(operating_system)>`__ processes
(see the `SQLite FAQ Q6 <https://sqlite.org/faq.html#q6>`__).
(Forking creates a child process that is a duplicate of the parent
including the state of all data structures in the program. If you
do this to SQLite then parent and child would both consider
themselves owners of open databases and silently corrupt each
other's work and interfere with each other's locks.)
One example of how you may end up using fork is if you use the
`multiprocessing module
<http://docs.python.org/library/multiprocessing.html>`__ which uses
fork to make child processes.
If you do use fork or multiprocessing on a platform that supports
fork then you **must** ensure database connections and their objects
(cursors, backup, blobs etc) are not used in the parent process, or
are all closed before calling fork or starting a `Process
<http://docs.python.org/library/multiprocessing.html#process-and-exceptions>`__.
(Note you must call close to ensure the underlying SQLite objects
are closed. It is also a good idea to call `gc.collect(2)
<http://docs.python.org/library/gc.html#gc.collect>`__ to ensure
anything you may have missed is also deallocated.)
I hope this is fixed. The main code so far was the music indexing process - and this is a full fork+exec now, so they don't share any resources. This is all in https://github.com/albertz/music-player/compare/1907bc4295...000793be69.
All these changes might have introduced other crashes. I encountered some while testing. Not sure if they are still they. But they seem unrelated anyway - so this can be closed.
This was reported by @christheswiss:
The related Python backtrace:
A very related crash: https://github.com/celery/celery/issues/869