panel
panel copied to clipboard
asyncio error on importing config with IPython
ALL software version info
- OS: Linux, Pop!_OS 22.04 LTS x86_64. Ubuntu variant
- Python: 3.9.18
- IPython: 8.18.1 (latest minor version compatible with python 3.9)
- panel: 1.3.8
- bokeh: 3.3.4
Description of expected behavior and the observed behavior
- Expected: importing
panel.configwill work in IPython environment - Actual:
RuntimeError: There is no current event loop in 'MainThread'. Relevant SO post
Complete, minimal, self-contained example code that reproduces the issue
from panel import config
Stack traceback and/or browser JavaScript console output
Run in python
Python 3.9.18 | packaged by conda-forge | (main, Aug 30 2023, 03:49:32)
[GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from panel import config
>>> config
_config(_admin=False, _admin_endpoint=None, _admin_log_level='DEBUG', _basic_auth=None, _comms='default', _console_output=None, _cookie_secret=None, _embed=None, _embed_json=False, _embed_json_prefix='', _embed_load_path=None, _embed_save_path='./', _inline=None, _log_level='WARNING', _npm_cdn='https://cdn.jsdelivr.net/npm', _nthreads=None, _oauth_encryption_key=None, _oauth_expiry=1, _oauth_extra_params={}, _oauth_guest_endpoints=None, _oauth_jwt_user=None, _oauth_key=None, _oauth_optional=False, _oauth_provider=None, _oauth_redirect_uri=None, _oauth_refresh_tokens=False, _oauth_secret=None, _theme=None, admin_plugins=[], apply_signatures=True, auth_template=None, authorize_callback=None, autoreload=False, basic_auth_template=None, browser_info=True, css_files=[], defer_load=False, design=None, disconnect_notification='', exception_handler=None, global_css=[], global_loading_spinner=False, js_files={}, js_modules={}, layout_compatibility='warn', load_entry_points=True, loading_color='#c3c3c3', loading_indicator=False, loading_max_height=400, loading_spinner='arc', name='_config00003', notifications=False, profiler=None, raw_css=[], ready_notification='', reuse_sessions=False, safe_embed=False, session_history=0, session_key_func=None, sizing_mode=None, template=None, throttled=False)
Run in IPython
I [1]: from panel import config
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from panel import config
File ~/miniconda3/envs/temp_p_0207/lib/python3.9/site-packages/panel/__init__.py:50
1 """
2 Panel is a high level app and dashboarding framework
3 ====================================================
(...)
46 https://panel.holoviz.org/getting_started/index.html
47 """
48 from param import rx
---> 50 from . import chat # noqa
51 from . import layout # noqa
52 from . import links # noqa
File ~/miniconda3/envs/temp_p_0207/lib/python3.9/site-packages/panel/chat/__init__.py:33
1 """
2 Panel chat makes creating chat components easy
3 ==============================================================
(...)
29 https://panel.holoviz.org/reference/chat/ChatInterface.html
30 """
31 import importlib as _importlib
---> 33 from .feed import ChatFeed # noqa
34 from .icon import ChatReactionIcons # noqa
35 from .interface import ChatInterface # noqa
File ~/miniconda3/envs/temp_p_0207/lib/python3.9/site-packages/panel/chat/feed.py:25
22 import param
24 from .._param import Margin
---> 25 from ..io.resources import CDN_DIST
26 from ..layout import Column, ListPanel
27 from ..layout.card import Card
File ~/miniconda3/envs/temp_p_0207/lib/python3.9/site-packages/panel/io/__init__.py:9
7 from .cache import cache # noqa
8 from .callbacks import PeriodicCallback # noqa
----> 9 from .document import ( # noqa
10 hold, immediate_dispatch, init_doc, unlocked, with_lock,
11 )
12 from .embed import embed_state # noqa
13 from .logging import panel_logger # noqa
File ~/miniconda3/envs/temp_p_0207/lib/python3.9/site-packages/panel/io/document.py:47
41 DISPATCH_EVENTS = (
42 ColumnDataChangedEvent, ColumnsPatchedEvent, ColumnsStreamedEvent,
43 ModelChangedEvent
44 )
46 WRITE_TASKS = []
---> 47 WRITE_LOCK = asyncio.Lock()
49 @dataclasses.dataclass
50 class Request:
51 headers : dict
File ~/miniconda3/envs/temp_p_0207/lib/python3.9/asyncio/locks.py:81, in Lock.__init__(self, loop)
79 self._locked = False
80 if loop is None:
---> 81 self._loop = events.get_event_loop()
82 else:
83 self._loop = loop
File ~/miniconda3/envs/temp_p_0207/lib/python3.9/asyncio/events.py:642, in BaseDefaultEventLoopPolicy.get_event_loop(self)
639 self.set_event_loop(self.new_event_loop())
641 if self._local._loop is None:
--> 642 raise RuntimeError('There is no current event loop in thread %r.'
643 % threading.current_thread().name)
645 return self._local._loop
RuntimeError: There is no current event loop in thread 'MainThread'.
Screenshots or screencasts of the bug in action
n/a
Contribution
- [X] I may be interested in making a pull request to address this
I would take the approach recommended in the SO post linked above
For now, our team will be pinning to an older version: panel<=1.3.4
Sadly I cannot reproduce, but would be happy to see a PR to fix this, e.g. by initializing the WRITE_LOCK with None and initializing it on the first write in _run_write_futures.