
I am running locally a bokeh app on ipython. When the application terminates, the server socket is not released, thus on the next run, the socket cannot be re-established.
Kindly educate what is the correct way to release a socket? Bokeh version is 3.4.1.
Below is a minimum reproducible example (saved as mre.py) and an example ipython session.
import sys
from bokeh.server.server import Server
def app_close(session_context):
print("Test done")
sys.exit()
def app_init(doc):
doc.title = "Close tab to terminate"
doc.on_session_destroyed(app_close)
return doc
server = Server({"/": app_init},
check_unused_sessions_milliseconds=500,
unused_session_lifetime_milliseconds=500,
)
if server._started == False:
server.start()
server.io_loop.add_callback(server.show, "/")
try:
server.io_loop.start()
except:
pass
An ipython session. Closing the browser tab and running the app second time yields an error.
C:\WPy64-31241\scripts>ipython
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.25.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: run "c:/Users/Heke/fartdetector/mre.py"
Test done
In [2]: run "c:/Users/Heke/fartdetector/mre.py"
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

