Skip to content

Commit

Permalink
Log error if attempt is made to use unlocked on the wrong thread
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 6, 2024
1 parent 6608244 commit f330a8b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion panel/io/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,15 @@ def unlocked() -> Iterator:
curdoc = state.curdoc
session_context = getattr(curdoc, 'session_context', None)
session = getattr(session_context, 'session', None)
if curdoc is None or session_context is None or session is None or state._jupyter_kernel_context:
if state._current_thread != state._thread_id:
logger.error(
"Using the unlocked decorator when running inside a thread "
"is not safe! Ensure you check that pn.state._current_thread "
"matches the current thread id."
)
yield
return
elif curdoc is None or session_context is None or session is None or state._jupyter_kernel_context:
yield
return
elif curdoc.callbacks.hold_value:
Expand Down

0 comments on commit f330a8b

Please sign in to comment.