from
flask
import
Flask, Response
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_socketio
import
SocketIO
from
threading
import
Lock
app
=
Flask(__name__)
db_str
=
"{}+{}://{}:{}@{}:{}/{}?charset=utf8"
app.config[
'SQLALCHEMY_DATABASE_URI'
]
=
db_str.
format
('')
db
=
SQLAlchemy()
socketio
=
SocketIO()
db.init_app(app)
socketio.init_app(app)
lockObj
=
None
thread_lock
=
Lock()
thread_flag
=
None
@app
.route(
'/'
)
def
run():
global
thread_flag
with thread_lock:
if
thread_flag
is
None
:
thread_flag
=
socketio.start_background_task(task)
return
Response(response
=
'success'
)
def
task():
print
(
' enter ... '
,
str
(db.engine))
if
__name__
=
=
'__main__'
:
app.config[
'JSON_AS_ASCII'
]
=
False
socketio.run(app)