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

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

Closed
mudassar111 opened this issue Oct 22, 2021 · 11 comments
Closed

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

mudassar111 opened this issue Oct 22, 2021 · 11 comments

Comments

@mudassar111
Copy link

mudassar111 commented Oct 22, 2021

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
Copy link
Owner

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

@mudassar111
Copy link
Author

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
Copy link
Author

mudassar111 commented Oct 25, 2021

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

@BugzTheBunny
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

Brother I am getting the same error @BugzTheBunny

@BugzTheBunny
Copy link
Owner

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
Copy link

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
Copy link

hey any updates on fixing this error.

@EPanni
Copy link

EPanni commented Aug 5, 2022

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
Copy link

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

image image

The output :
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants