plotly / plotly/dash

cannot pickle 'SSLContext' with background callback

Open
#2,827 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

Describe your context

Windows 11, Python 3.9

dash                      2.16.1                                                                                               
dash-bootstrap-components 1.4.1                                                                                                
dash-core-components      2.0.0                                                                                                
dash-html-components      2.0.0                                                                                                
dash-table                5.0.0

Occurs with Edge & Chrome.

Describe the bug

I use a background callback in a multi-page app that throws an error when called:

  • TypeError: cannot pickle 'SSLContext' object in the browser (without more details, see screenshot below)
  • in the standard output:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\201021305\.conda\envs\track\lib\site-packages\multiprocess\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "C:\Users\201021305\.conda\envs\track\lib\site-packages\multiprocess\spawn.py", line 126, in _main
    self = reduction.pickle.load(from_parent)
  File "C:\Users\201021305\.conda\envs\track\lib\site-packages\dill\_dill.py", line 289, in load
    return Unpickler(file, ignore=ignore, **kwds).load()
  File "C:\Users\201021305\.conda\envs\track\lib\site-packages\dill\_dill.py", line 444, in load
    obj = StockUnpickler.load(self)
EOFError: Ran out of input

Here's how the callback is defined:

BACKGROUND_CALLBACK_MANAGER = dash.DiskcacheManager(diskcache.Cache("./cache"))
@dash.callback(
    [...]
    prevent_initial_call=True,
    background=True,
    manager=BACKGROUND_CALLBACK_MANAGER,
)

The callback involves an object that has a SQLAlchemy engine as an attribute. The connection is made through SSL, so I guess this is the object that fails to be pickled. However, I can serialize this object successfully with dill.dumps, so I'm not sure...

Maybe related to https://github.com/uqfoundation/dill/issues/308, but until the issue is fixed, there might be a workaround?

Expected behavior

I expect the callback to run without error.

Screenshots

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the background callback definition using dash.callback and DiskcacheManager, then reproduce the Windows 11/Python 3.9 failure with the SQLAlchemy engine involved. Trace where the callback is serialized for the background worker; done means the callback runs without the SSLContext pickling error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.