0

every time i run the code i see Serving Flask-SocketIO app "app.py"

i don't even have SpcketIO on my system

import os, passlib ,requests ,time ,json
from flask import Flask, session , render_template , request,redirect,url_for ,jsonify 
from flask_session import Session
import pandas as pd
from flask_uploads import UploadSet, configure_uploads, IMAGES, patch_request_class
from werkzeug import secure_filename
from datetime import date , datetime
from flask_sqlalchemy import SQLAlchemy
from passlib.hash import sha256_crypt
from flask_login import LoginManager , UserMixin , current_user ,login_user ,login_required ,logout_user

app = Flask(__name__)

by the end of my code I've this

if __name__ == "__main__":
app.run(debug=True)

i run the system by cmd: flask run

I used to ignore this error as everything else was working but when i tried to add app.run(debug=True,host='0.0.0.0')

also debug=True didn't seem to be doing anything anymore i had to turn it on through the CMD set Flask_Debug=1

i got an error stating ValueError: signal only works in main thread

and the app didn't run at all

the exact error

 * Serving Flask-SocketIO app "app.py"
 * Forcing debug mode on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 885-769-473
Exception in thread Thread-1:
Traceback (most recent call last):
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\threading.py
", line 917, in _bootstrap_inner
    self.run()
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\threading.py
", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\flask_socketio\cli.py", line 59, in run_server
    return run_command()
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\flask\cli.py", line 771, in run_command
    threaded=with_threads, ssl_context=cert)
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\werkzeug\serving.py", line 812, in run_simple
    reloader_type)
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\site-package
s\werkzeug\_reloader.py", line 267, in run_with_reloader
    signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
  File "c:\users\mena\appdata\local\programs\python\python37-32\lib\signal.py",
line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread

to get back to work i had to turn off the debug in cmd set Flask_Debug=0

what's wrong with my system ?

LoopingDev
  • 754
  • 2
  • 10
  • 32
  • Is your process get terminated? Do you get any trace back or debug window? – Shriniwas Dec 23 '18 at 10:06
  • nope it closes gently but i'll add the exact lines it prints before `ValueError` part – LoopingDev Dec 23 '18 at 10:09
  • you can show !! – Shriniwas Dec 23 '18 at 10:10
  • please check if there is any other thread running or not. And try running your app by command python app.py from terminal instead of flask run. may be flask run command invoking other services to which are not necessary to your application. – Shriniwas Dec 23 '18 at 10:20
  • there are no other python apps running in the back ground but could you tell me what i should do exactly as i'm a new dev i am not sure how to run the app without `flask run` i can google it but i'm worried that i might get the wrong answer – LoopingDev Dec 23 '18 at 10:23
  • I am assuming you are working on Linux system. In terminal (Windows cmd) and in your project directory where your app.py is located just enter python (python/python3 depnds whichever version you are using) app.py and hit enter. – Shriniwas Dec 23 '18 at 10:28
  • `* Serving Flask app "app" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: on * Restarting with stat * Debugger is active! * Debugger PIN: 326-124-708 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)` – LoopingDev Dec 23 '18 at 10:50
  • it seems to be working Thank you ! - no Socket-IO in the system but also i tried to access the app from different device use 127.0.0.1:5000 , i got nothing , does this means host='0.0.0.0' didnt work ? – LoopingDev Dec 23 '18 at 10:51
  • Possible duplicate of [Flask APP - ValueError: signal only works in main thread](https://stackoverflow.com/questions/53522052/flask-app-valueerror-signal-only-works-in-main-thread) – rfkortekaas Dec 23 '18 at 11:15

1 Answers1

0

please check if there is any other thread running or not. And try running your app by command python app.py from terminal instead of flask run. may be flask run command invoking other services to which are not necessary to your application.

Also I am assuming you are working on Linux system. In terminal (Windows cmd) and in your project directory where your app.py is located just enter python (python/python3 depnds whichever version you are using) app.py and hit enter.

try this on command line

python app.py
or
python3 app.py
Shriniwas
  • 664
  • 3
  • 11
  • 25
  • Your answer is missing some information, but will work. See my answer in [this duplicate](https://stackoverflow.com/questions/53522052/flask-app-valueerror-signal-only-works-in-main-thread?noredirect=1#comment93938442_53522052) which is more complete! – rfkortekaas Dec 23 '18 at 11:18