Python 在执行下一个命令之前不渲染Rails
我使用的是Rails 4,我想在编辑控制器后执行Python脚本 我已经做到了:Python 在执行下一个命令之前不渲染Rails,python,ruby-on-rails,exec,thin,webrick,Python,Ruby On Rails,Exec,Thin,Webrick,我使用的是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 ne
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配置。正在重新启动设备,这将需要一段时间…'。韦布里克等了10秒钟,然后倒下
我试过Webrick和thin,他们都是这样做的 如果我理解得很好:您希望您的控制器在python脚本完成之前呈现一个响应 使用线程允许同时运行多个代码块,我认为您希望像后台作业一样执行python脚本 相反,要使用线程,请查看[delayed_job gem][1]。这个gem在后台封装并执行更长的任务