Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop_Server() Is not working to close the server when show_dash() is called in a separate thread #179

Open
Jamesong7822 opened this issue Mar 23, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Jamesong7822
Copy link

Jamesong7822 commented Mar 23, 2023

Hi, here's a MWE to reproduce this issue:
Here are the module versions:

  1. plotly-resampler==0.8.3.1
  2. Flask==2.1.3
  3. jupyter-dash==0.4.2
  4. Werkzeug==2.1.2
import plotly.graph_objects as go; import numpy as np
from plotly_resampler import FigureResampler
import time
import threading

x = np.arange(1_000_000)
sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_000

fig = FigureResampler(go.Figure())
fig.add_trace(go.Scattergl(name='noisy sine', showlegend=True), hf_x=x, hf_y=sin)

threading.Thread(target=fig.show_dash, kwargs={"mode": "external", "port":8050}, daemon=True).start()

start_time = time.time()
while True:
    if time.time() - start_time > 10:
        print("Time to stop!")
        fig.stop_server()
        print("Stop server ran!")
        break

# This loop is meant to keep the script alive
while True:
    pass

If the fig.stop_server() function is working, refreshing the browser: 127.0.0.1:8050 should yield a "SITE CANNOT BE REACHED ERROR" which is expected if the dash server is functional.

However, that is not the case, and the server is still alive. Please kindly advise, how one can go about terminating the server, without having to terminate the entire python script.

@jvdd
Copy link
Member

jvdd commented Apr 4, 2023

Hey @Jamesong7822,

Thx for submitting this issue together with the qualitative reproducible code :)

I ran this code on my machine, but could not reproduce the bug (the server stops after 10s, and I get this This site can’t be reached in the browser when I reload).

Are you by any chance working on Windows? I'm not an expert on this, but I do know that multiprocessing (& possibly threading) on Windows is performed differently than on Unix systems...

Hope to get this sorted out!

Cheers, Jeroen

P.S.: my apologies for the late response - had some paper deadlines that limited my spare time (to work on open-source contributions)

@jonasvdd jonasvdd added the bug Something isn't working label Jul 4, 2023
@jonasvdd
Copy link
Member

jonasvdd commented Jul 4, 2023

I further looked into this, and it appears that this code works as-expected when running this within a Jupyter cell (using Ipython kernel); this activates the JupyterDash component of Dash which allows (for some yet unknown reason, to behave as expected).

If you use this as a python script, this code does not work as expected, and the just-started server is not found in the server_dict and can thus be not killed.

This issue thus needs further follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants