Python socket.io 流数据和常量发出而不冻结

问题描述

我有一个运行 socket.io 的简单 python 服务器

基本上我想做的是让它不断地发出新数据,有点像视频流。这应该没有任何延迟,每秒发生几次。

这是我到目前为止的代码。问题是每当流事件开始时,其他客户端都无法连接。

基本上,一旦我弄清楚如何保持服务器响应

import tensorflow as tf
from model import Transformer
from tqdm import tqdm
from data_load import get_batch
from utils import save_hparams,save_variable_specs,get_hypotheses,calc_bleu
import os
from hparams import Hparams
import math
import logging
import horovod.tensorflow as hvd

os.environ['CUDA_VISIBLE_DEVICES'] = ','.join(hp.multi_model)
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
config.allow_soft_placement=True

train_batches,num_train_batches,num_train_samples = get_batch(hp.train1,hp.train2,hp.maxlen1,hp.maxlen2,hp.vocab,hp.batch_size,shuffle=True)

iter = tf.data.Iterator.from_structure(train_batches.output_types,train_batches.output_shapes)
train_init_op = iter.make_initializer(train_batches)
xs,ys = iter.get_next()
logging.info("# Load model")
m = Transformer(hp)
loss = m.train(xs,ys)

global_step = tf.train.get_or_create_global_step()

total_steps = hp.num_epochs * num_train_batches
stop_hook = tf.train.StopAtStepHook(last_step=total_steps)
hooks = [hvd.broadcastGlobalVariablesHook(0),stop_hook]
checkpoint_dir = hp.logdir if hvd.rank() == 0 else None

with tf.train.MonitoredTrainingSession(checkpoint_dir=checkpoint_dir,config=config,hooks=hooks) as sess:

    sess.run(train_init_op)
    optimizer = tf.train.AdamOptimizer(hp.lr * hvd.size())
    optimizer = hvd.distributedOptimizer(optimizer)
    train_op = optimizer.minimize(loss,global_step=global_step)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)