Skip to content

Stopping a server in a Notebook on Python 3.13 stops event loop #7713

Description

@hoxbro

First seen in holoviz/holoviews#6508

# Cell 1
import panel as pn
server = pn.panel("s").show()

# Cell 2
server.stop()
pn.state.add_periodic_callback(lambda: print(1))
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[2], line 3
      1 # Cell 2
      2 server.stop()
----> 3 pn.state.add_periodic_callback(lambda: print(1))

File [~/projects/holoviz/repos/panel/panel/io/state.py:584](http://localhost:8888/home/shh/projects/holoviz/repos/panel/panel/io/state.py#line=583), in _state.add_periodic_callback(self, callback, period, count, timeout, start)
    580 cb = PeriodicCallback(
    581     callback=callback, period=period, count=count, timeout=timeout
    582 )
    583 if start:
--> 584     cb.start()
    585 if self.curdoc:
    586     if self.curdoc not in self._periodic:

File [~/projects/holoviz/repos/panel/panel/io/callbacks.py:175](http://localhost:8888/home/shh/projects/holoviz/repos/panel/panel/io/callbacks.py#line=174), in PeriodicCallback.start(self)
    173         self._doc.add_next_tick_callback(self.start)
    174 else:
--> 175     self._cb = asyncio.create_task(
    176         self._async_repeat(self._periodic_callback)
    177     )

File [~/.local/conda/envs/holoviz13/lib/python3.13/asyncio/tasks.py:407](http://localhost:8888/home/shh/.local/conda/envs/holoviz13/lib/python3.13/asyncio/tasks.py#line=406), in create_task(coro, name, context)
    402 def create_task(coro, *, name=None, context=None):
    403     """Schedule the execution of a coroutine object in a spawn task.
    404 
    405     Return a Task object.
    406     """
--> 407     loop = events.get_running_loop()
    408     if context is None:
    409         # Use legacy API if context is not needed
    410         task = loop.create_task(coro, name=name)

RuntimeError: no running event loop

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions