Hi all,
I have a bit of a tricky bug with background callbacks on Mac with Python3.11 and would greatly appreciate any input regarding the issue itself or how to draft a good bug report for Issues · plotly/dash · GitHub
Problem Description
Running the example from Background Callback Caching | Dash for Python Documentation | Plotly on a MacBook Pro with Python 3.11 starts up fine but when clicking the “Run Job!” button yields the following error:
Process Process-2:
Traceback (most recent call last):
File "/Users/ndr/code/test_caching/.venv/lib/python3.11/site-packages/multiprocess/process.py", line 314, in _bootstrap
self.run()
File "/Users/ndr/code/test_caching/.venv/lib/python3.11/site-packages/multiprocess/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/Users/ndr/code/test_caching/.venv/lib/python3.11/site-packages/dash/long_callback/managers/diskcache_manager.py", line 197, in job_fn
ctx.run(run)
File "/Users/ndr/code/test_caching/.venv/lib/python3.11/site-packages/dash/long_callback/managers/diskcache_manager.py", line 195, in run
cache.set(result_key, user_callback_output)
File "/Users/ndr/code/test_caching/.venv/lib/python3.11/site-packages/diskcache/core.py", line 800, in set
with self._transact(retry, filename) as (sql, cleanup):
File "/Users/ndr/.pyenv/versions/3.11.8/lib/python3.11/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "/Users/ndr/code/test_caching/.venv/lib/python3.11/site-packages/diskcache/core.py", line 714, in _transact
sql = self._sql
^^^^^^^^^
File "/Users/ndr/code/test_caching/.venv/lib/python3.11/site-packages/diskcache/core.py", line 652, in _sql
return self._con.execute
^^^^^^^^^
File "/Users/ndr/code/test_caching/.venv/lib/python3.11/site-packages/diskcache/core.py", line 623, in _con
con = self._local.con = sqlite3.connect(
^^^^^^^^^^^^^^^^
sqlite3.OperationalError: disk I/O error
When running the same code under Python3.10 on the same machine it works without problems.
Running the same code with Python3.11 under either Windows or Ubuntu also works fine.
Mitigation attempts
Going back to the Mac with Python3.11 and disabling debug mode of the app e.g.
app.run(debug=False)
Makes the error only come up sometimes i.e. sometimes, the click leads to a page update and sometimes to the sqlite3 disk I/O error.
Additionally disabling threading and using only a single process
app.run(debug=False, processes=1, threaded=False)
makes the error go away and the page working “properly” but severely limiting the usage of debug mode and threading.
To me, it seems to be a multiprocessing file access issue specific to Mac (maybe related to forking?) but I am not familiar with debugging these kind of issues, specifically with a Mac.
I tried additionally allowing “Full Disk Access” to the Terminal and my IDE and setting the environment variable OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
(as I googled this might be related somewhere else) but that did not appear to change anything.