flask socketIO 多处理值

flask socketIO multiprocessing Value

我正在尝试使用多处理值更新数据元素 多处理函数。数据值更新不超过一次。我已阅读以下页面和其他问题: 我想知道 Flask 应用程序是否在干扰......?

https://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent
http://timmyreilly.azurewebsites.net/flask-socketio-and-more/
https://github.com/miguelgrinberg/Flask-SocketIO/issues/356

这是一个 flask、wtf、socketio、bootstrap、python 2.7 应用程序。 除数据价值份额外的所有作品。

app = Flask(__name__)
app.config['SECRET_KEY'] = os.urandom(24)
Bootstrap(app)
socketio = SocketIO(app)
mp_date = Value('f', 0.0, lock=False)  

if __name__ == '__main__':
operation_run = multiprocessing.Process(target=sys_operations,args=((parent_conn, child_conn),True, mp_date)) 

operation_run.start()
socketio.run(app, host='0.0.0.0', debug=True,use_reloader=False)

In the multiprocessed function 
def orerry_operations(pipe, first_run, mp_date):
….
    mp_date.value=moving_date  #this is the update that does not work,
                moving_date is a float
    print 'mp_date obj: ' + str(mp_date)
    print 'mp_date  ' + str(mp_date.value)
    print 'moving_date  ' + str(moving_date)

the print results are:
mp_date obj: c_float(581948928.0)
mp_date  581948928.0
moving_date  581948957.797

mp_date obj: c_float(581948928.0)
mp_date  581948928.0
moving_date  581948959.814

mp_date obj: c_float(581948992.0)
mp_date  581948992.0
moving_date  581948961.83

如您所见,mp_date 值未更新。 好像是第一次设置, 然后不是随后。
我不加入,因为该功能持续运行。 帮忙?

您需要在函数的开头指定 orerry_operations:

global mp_date