【问题标题】:Rails not rendering before execute next commandRails 在执行下一个命令之前不渲染
【发布时间】:2014-07-31 07:16:46
【问题描述】:

我正在使用 Rails 4,我想在编辑控制器后执行 Python 脚本。

我已经完成了:

 if @a_serverconfiguration.update(a_serverconfiguration_params)
    format.html { redirect_to @a_serverconfiguration, notice: 'Device configuration was successfully updated. Next time, you have to access to new ip configuration. Rebooting device, this would take a while...' }
   format.json { render :show, status: :ok, location: @a_serverconfiguration }
Thread.new do      
    exec "sudo python /home/pi/Desktop/starting.py"
end
  else
    format.html { render :edit }
    format.json { render json: @a_serverconfiguration.errors, status: :unprocessable_entity }
  end
end

但是在执行 python 脚本之前我看不到我的显示页面。此脚本在 10 秒后重新启动,因此当用户更新控制器时,看不到消息“设备配置已成功更新。下次,您必须访问新的 ip 配置。重新启动设备,这将需要一段时间......'。 Webrick 等待 10 秒后下线。

我已经尝试过使用 Webrick 和 Thin,两者都做同样的事情。

【问题讨论】:

    标签: python ruby-on-rails exec thin webrick


    【解决方案1】:

    如果我理解得很好:您希望您的控制器在 Python 脚本完成之前呈现响应。

    使用线程允许同时运行多个代码块,我想你想像后台作业一样执行你的 python 脚本。

    如果要使用 Thread,请查看 [delayed_job gem][1]。这个 gem 封装并在后台执行更长的任务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 2019-12-31
      • 1970-01-01
      • 2018-04-03
      • 2018-07-17
      • 1970-01-01
      相关资源
      最近更新 更多