You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use flask_apscheduler to run a scheduled task, and the scheduled task involves a multiprocess task. What's more, I deploy my app with uwsgi, and then I get this error:
Sun Nov 20 22:39:00 2022 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) !!!
Sun Nov 20 22:39:01 2022 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) !!!
Sun Nov 20 22:39:01 2022 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) !!!
Sun Nov 20 22:39:02 2022 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) !!!
Sun Nov 20 22:39:02 2022 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) !!!
Sun Nov 20 22:39:06 2022 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) !!!
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/home/tops/lib/python3.7/concurrent/futures/thread.py", line 40, in _python_exit
t.join()
File "/home/tops/lib/python3.7/threading.py", line 1029, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
My code is like:
fromflaskimportFlaskimportfcntlimportatexitapp=Flask(__name__)
# use a file lock to solve the problem of multiple runscheduler_lock=Falsetry:
f=open("scheduler.lock", "wb")
fcntl.flock(f, fcntl.LOCK_EX|fcntl.LOCK_NB)
scheduler_lock=Trueexcept:
passifscheduler_lock:
importtimefromfunctoolsimportpartialfrommultiprocessingimportPoolfromdatetimeimportdatetime, timedeltafromflask_apschedulerimportAPSchedulera, b, c, d=None, None, None, None# setting schedulerscheduler=APScheduler()
# scheduler.api_enabled = Truescheduler.init_app(app)
scheduler.start()
@scheduler.task('interval', id='my_job', minutes=30, next_run_time=datetime.now())defmy_job():
globala, b, c, drun_task_partial=partial(
mp_task, a=a, b=b, c=c, d=d)
p=Pool(worker_num)
withPool(worker_num) asp:
result=p.map(run_task_partial, keys)
defunlock():
fcntl.flock(f, fcntl.LOCK_UN)
f.close()
# register unlockatexit.register(unlock)
# It is a normal flask app without lock@app.route('/checkpreload.htm')defcheckpreload():
return'success'@app.route('/')defhome():
return'Hello World'if__name__=='__main__':
app.run(host='0.0.0.0', debug=True, port=7001, use_reloader=False)
This discussion was converted from issue #4872 on November 21, 2022 02:53.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I use flask_apscheduler to run a scheduled task, and the scheduled task involves a multiprocess task. What's more, I deploy my app with uwsgi, and then I get this error:
My code is like:
And my uwsgi config is:
Environment:
uWSGI>=2.0.18 APScheduler==3.9.1 Flask==2.2.2 Flask-APScheduler==1.12.3
Beta Was this translation helpful? Give feedback.
All reactions