BugzTheBunny / streamlit_navbar

An example of how to make an streamlit app with a navbar.
119 stars 33 forks source link

signal only works in main thread of the main interpreter #1

Closed mudassar111 closed 2 years ago

mudassar111 commented 2 years ago

I am getting this error "signal only works in main thread of the main interpreter". Can you please explain it to me, how can I rid of it? @BugzTheBunny

BugzTheBunny commented 2 years ago

Could you elaborate more? how can I recreate it? didn't see it happen.

mudassar111 commented 2 years ago

ValueError: signal only works in main thread of the main interpreter

File "C:\Python39\lib\site-packages\streamlit\script_runner.py", line 354, in _run_script exec(code, module.dict) File "C:\Python39\streamlit_navbar-main\application.py", line 24, in app.run(debug=True) File "C:\Python39\lib\site-packages\flask\app.py", line 922, in run run_simple(t.cast(str, host), port, self, *options) File "C:\Python39\lib\site-packages\werkzeug\serving.py", line 1000, in run_simple _rwr( File "C:\Python39\lib\site-packages\werkzeug_reloader.py", line 411, in run_with_reloader signal.signal(signal.SIGTERM, lambda args: sys.exit(0)) File "C:\Python39\lib\signal.py", line 47, in signal handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))

mudassar111 commented 2 years ago

This is the error I got when I run "application.py" file @BugzTheBunny

BugzTheBunny commented 2 years ago

Hi @mudassar111 sorry for the late response,

You are saying that when trying to run the code as it is in this repo, this is the Error that you are getting? If so, can you try to rerun it with a different python version? 3.8 for example? because it's really odd, I tried to rerun it, and everything works fine, even with the newest Streamlit version..

mudassar111 commented 2 years ago

ValueError: signal only works in main thread Traceback:

File "c:\python38\lib\site-packages\streamlit\script_runner.py", line 354, in _run_script exec(code, module.dict) File "C:\Python38\streamlit_navbar-main\application.py", line 24, in app.run(debug=True) File "c:\python38\lib\site-packages\flask\app.py", line 920, in run run_simple(t.cast(str, host), port, self, *options) File "c:\python38\lib\site-packages\werkzeug\serving.py", line 1002, in run_simple _rwr( File "c:\python38\lib\site-packages\werkzeug_reloader.py", line 411, in run_with_reloader signal.signal(signal.SIGTERM, lambda args: sys.exit(0)) File "c:\python38\lib\signal.py", line 47, in signal handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))

mudassar111 commented 2 years ago

Brother I am getting the same error @BugzTheBunny

BugzTheBunny commented 2 years ago

Hey @mudassar111,

It appears the problem is not related to the code, you should read this thread - https://stackoverflow.com/questions/54749342/valueerror-signal-only-works-in-main-thread

Cheers

chiehpower commented 2 years ago

Encountered the same issue here.

$ streamlit run application.py                                                           

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://10.1.2.84:8501

 * Serving Flask app 'application' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
2022-04-07 13:55:12.448  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2022-04-07 13:55:12.449 Traceback (most recent call last):
  File "/home/chieh/.local/lib/python3.8/site-packages/streamlit/script_runner.py", line 430, in _run_script
    exec(code, module.__dict__)
  File "/home/chieh/472GB/github/streamlit_navbar/application.py", line 13, in <module>
    app.run(debug=True)
  File "/home/chieh/.local/lib/python3.8/site-packages/flask/app.py", line 920, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/home/chieh/.local/lib/python3.8/site-packages/werkzeug/serving.py", line 1002, in run_simple
    _rwr(
  File "/home/chieh/.local/lib/python3.8/site-packages/werkzeug/_reloader.py", line 411, in run_with_reloader
    signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
  File "/usr/lib/python3.8/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
thestonedape commented 2 years ago

hey any updates on fixing this error.

EPanni commented 2 years ago

Hello @thestonedape , (Trying to help)

That is not in the same context but I hope it can give you some insights. 👍

I came across a similar issue in my application when using (flask_socketio) and it was solved by disabling the debug mode.

Reason: When you run in Debug, the reloader expects to run in the main thread.

web_socket = Thread(target=socketio.run, args=(app,), kwargs={'host':'0.0.0.0', 'port': , 'debug':False, use_reloader':False})

yohanespm77 commented 1 year ago

Hello @BugzTheBunny , why folium cannot be displayed in streamlit_navbar ?

image image

The output :

image