I’m trying to get background callback to work with diskcache. The example works find (sleep for 1 second, etc), but when I try to use my real function (which makes an api request using the requests
package), i get this:
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
Is this typical? I’m on a new M1 mac, i thought maybe that could be the problem? Or my python version (which i’ve tried everywhere from 3.6 to 3.11).
Hello @aboyher,
I was able to use requests:
code:
import time
import os
import dash
from dash import DiskcacheManager, CeleryManager, Input, Output, html
import requests
if 'REDIS_URL' in os.environ:
# Use Redis & Celery if REDIS_URL set as an env variable
from celery import Celery
celery_app = Celery(__name__, broker=os.environ['REDIS_URL'], backend=os.environ['REDIS_URL'])
background_callback_manager = CeleryManager(celery_app)
else:
# Diskcache for non-production apps when developing locally
import diskcache
cache = diskcache.Cache("./cache")
background_callback_manager = DiskcacheManager(cache)
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.Div([html.P(id="paragraph_id", children=["Button not clicked"])]),
html.Button(id="button_id", children="Run Job!"),
]
)
@dash.callback(
output=Output("paragraph_id", "children"),
inputs=Input("button_id", "n_clicks"),
background=True,
manager=background_callback_manager,
)
def update_clicks(n_clicks):
time.sleep(2.0)
r = requests.get('https://google.com')
return [r.content]
if __name__ == "__main__":
app.run_server(debug=True)
I did finally figure this out. It turns out, I was importing a package that was importing something from turtle for some reason, and not even using it. Once I removed that import, everything worked like a charm.
1 Like