当前位置: 首页 > news >正文

wordpress主题打不开天津做网站优化的公司

wordpress主题打不开,天津做网站优化的公司,网站弹出框怎么做,深圳品牌衣服店名称支持 input 函数的在线 python 运行环境 - 基于队列 思路两次用户输入三次用户输入 实现前端使用 vue element uiWindows 环境的执行器子进程需要执行的代码 代码仓库参考 本文提供了一种方式来实现支持 input 函数#xff0c;即支持用户输的在线 python 运行环境。效果如下图… 支持 input 函数的在线 python 运行环境 - 基于队列 思路两次用户输入三次用户输入 实现前端使用 vue element uiWindows 环境的执行器子进程需要执行的代码 代码仓库参考 本文提供了一种方式来实现支持 input 函数即支持用户输的在线 python 运行环境。效果如下图所示 思路 前端使用一个数组 input_queue 记录用户从点击运行按钮到现在的所有输入 点击运行按钮时将 code、input_queue 传给后端 后端将参数传给执行 python 代码的子进程 子进程重写 input() 函数假设新的实现为 input_wrapper代码如下到用户代码运行到 input() 函数时会执行重写的 input_wrapper() 在 input_wrapper 中获取到 input_queue然后使用 input_queue.pop(0) 弹出用户输入最早的信息如果 input_queue 为空则说明需要用户输入通过抛出 InputRequestException 异常的方式通知后端 def input_wrapper(prompt):if input_queue:input_str input_queue.pop(0)sys.stdout.write(str(prompt) input_str \n)return input_strraise InputRequestException(str(prompt))后端通过处理子进程的标准输出、标准错误知晓需要用户输入然后向前端返回以下 jsonevent.type 为 input_request 代表需要用户输入prompt 是提示信息 {is_timeout: false,done: false,event: {type: input_request,prompt: 请输入姓名} }前端弹出弹框提示用户输入用户输入并点击继续执行按钮时会将本次的输入追加到 input_queue 的末尾然后再次调用运行接口这样循环往复直到程序结束 在执行以下代码时可能需要两次用户输入也可能需要三次。 name input(请输入姓名) print(姓名, name)if name tom:age input(请输入年龄)print(年龄, age)gender input(请输入性别) print(性别, gender)两次用户输入 点击运行按钮 请求参数中的 input_queue 为 []{code: name input(\请输入姓名\)\nprint(\姓名\, name)\n\nif name \tom\:\n age input(\请输入年龄\)\n print(\年龄\, age)\n\ngender input(\请输入性别\)\nprint(\性别\, gender),input_queue: [] }返回值 {is_timeout: false,done: false,event: {type: input_request,prompt: 请输入姓名} }输入 jack 请求参数中的 input_queue 为 [jack]{code: name input(\请输入姓名\)\nprint(\姓名\, name)\n\nif name \tom\:\n age input(\请输入年龄\)\n print(\年龄\, age)\n\ngender input(\请输入性别\)\nprint(\性别\, gender),input_queue: [jack] }返回值 {is_timeout: false,done: false,event: {type: input_request,prompt: 请输入性别} }输入 男 请求参数中的 input_queue 为 [jack, 男] {code: name input(\请输入姓名\)\nprint(\姓名\, name)\n\nif name \tom\:\n age input(\请输入年龄\)\n print(\年龄\, age)\n\ngender input(\请输入性别\)\nprint(\性别\, gender),input_queue: [jack,男] }返回值 {is_timeout: false,done: true,output: 请输入姓名jack\r\n姓名 jack\r\n请输入性别男\r\n性别 男\r\n }三次用户输入 点击运行按钮 请求参数中的 input_queue 为 [] {code: name input(\请输入姓名\)\nprint(\姓名\, name)\n\nif name \tom\:\n age input(\请输入年龄\)\n print(\年龄\, age)\n\ngender input(\请输入性别\)\nprint(\性别\, gender),input_queue: [] }返回值 {is_timeout: false,done: false,event: {type: input_request,prompt: 请输入姓名} }输入 tom 请求参数中的 input_queue 为 [tom] {code: name input(\请输入姓名\)\nprint(\姓名\, name)\n\nif name \tom\:\n age input(\请输入年龄\)\n print(\年龄\, age)\n\ngender input(\请输入性别\)\nprint(\性别\, gender),input_queue: [tom] }返回值 {is_timeout: false,done: false,event: {type: input_request,prompt: 请输入年龄} }输入 18 请求参数中的 input_queue 为 [tom, 18] {code: name input(\请输入姓名\)\nprint(\姓名\, name)\n\nif name \tom\:\n age input(\请输入年龄\)\n print(\年龄\, age)\n\ngender input(\请输入性别\)\nprint(\性别\, gender),input_queue: [tom,18] }返回值 {is_timeout: false,done: false,event: {type: input_request,prompt: 请输入性别} }输入 男 请求参数中的 input_queue 为 [tom, 18, 男] {code: name input(\请输入姓名\)\nprint(\姓名\, name)\n\nif name \tom\:\n age input(\请输入年龄\)\n print(\年龄\, age)\n\ngender input(\请输入性别\)\nprint(\性别\, gender),input_queue: [tom,18,男] }返回值 {is_timeout: false,done: true,output: 请输入姓名tom\r\n姓名 tom\r\n请输入年龄18\r\n年龄 18\r\n请输入性别男\r\n性别 男\r\n }实现 前端使用 vue element ui !DOCTYPE html html lang styleheight: 100%; headmeta charsetUTF-8link relstylesheet href./element-ui/index.csstitle在线 python 执行/title /head body styleheight: 100%;margin: 0; div idapp styleheight: 98%;width: 98%;padding: 5pxel-inputtypetextarea:autosize{ minRows: 10, maxRows: 100}placeholder请输入代码v-modelcode/el-inputel-button typeprimary stylemargin-top: 5px;margin-bottom: 5px clickexec()运行/el-buttonel-inputtypetextarea:autosize{ minRows: 10, maxRows: 100}placeholder运行结果v-modelresult/el-input /div /body script src./axios.min.js/script script src./vue.js/script script src./element-ui/index.js/script scriptnew Vue({el: #app,mounted() {},methods: {exec() {const params {code: this.code,input_queue: this.input_queue}axios.post(http://localhost:8080/exec, params).then(res {console.log(exec, res)if (res.data.done) {// 执行结束了需要清空队列this.clearQueue()if (res.data.is_timeout) {// 执行超时this.$message(执行超时);} else {// 正常执行结束this.result res.data.output}} else {// 执行中需要用户输入const event res.data.eventif (event.type input_request) {// 弹框提示用户输入this.$prompt(event.prompt, 输入, {confirmButtonText: 继续执行,cancelButtonText: 终止执行,showClose: false,closeOnClickModal: false,closeOnPressEscape: false}).then(({value}) {// 继续执行将本次输入的信息追加进队列然后再次执行this.input_queue.push(value)this.exec()}).catch((action) {// 终止执行需要清空队列console.log(action , action)this.clearQueue()this.$message(终止执行)});}}})},clearQueue() {this.input_queue []}},data() {return {code: name input(请输入姓名) print(姓名, name)if name tom:age input(请输入年龄)print(年龄, age)gender input(请输入性别) print(性别, gender) ,input_queue: [],result: null,}}})/script /htmlWindows 环境的执行器 import json import os import subprocess import threading from threading import Timerimport psutilclass AbstractExecutor:def __init__(self, param):# param 包括 code、input_queueself.param param# 用于保护 is_timeout 的锁self.lock threading.Lock()# 是否执行超时了self.is_timeout Nonedef timeout_callback(self, p: subprocess.Popen):执行超时时的回调会终止执行 python 代码的进程组:param p: 执行 python 代码的进程with self.lock:if self.is_timeout is None:self.is_timeout Trueif self.is_timeout:try:# 终止执行 python 代码的进程组self.terminating_process_group(p)except Exception as e:print(超时回调异常, error: %s, e)def terminating_process_group(self, p: subprocess.Popen):终止进程 p 及其子进程:param p: 要终止的进程raise NotImplementedError()def create_popen(self) - subprocess.Popen:创建 subprocess.Popen必须将 stderr 重定向到 stdoutraise NotImplementedError()def output(self, stdout):if stdout is not None:return stdout.decode(utf-8)else:return def execute(self):p self.create_popen()timer Timer(3, self.timeout_callback, [p])timer.start()try:# 从标准输入传入 json 参数code、input_queuep.stdin.write(json.dumps(self.param).encode(encodingutf-8))stdout, stderr p.communicate()with self.lock:if self.is_timeout is None:self.is_timeout Falsefinally:timer.cancel()return self.is_timeout, self.output(stdout)class WindowsExecutor(AbstractExecutor):__output_prefix Active code page: 65001\r\ndef create_popen(self) - subprocess.Popen:filename rD:\project\python\online-python-code-executor\queue-base\exec_py.pycmd chcp 65001 set PYTHONIOENCODINGutf-8 python filename# 将 stderr 重定向到了 stdoutreturn subprocess.Popen(cmd, stdinsubprocess.PIPE, stdoutsubprocess.PIPE, stderrsubprocess.STDOUT,shellTrue)def terminating_process_group(self, p: subprocess.Popen):proc_pid p.pidparent_proc psutil.Process(proc_pid)for child_proc in parent_proc.children(recursiveTrue):print(child_proc.pid)child_proc.kill()parent_proc.kill()print(parent_proc.pid)def output(self, stdout):output super().output(stdout)if output.startswith(self.__output_prefix):return output.removeprefix(self.__output_prefix)else:return outputif os.name nt:executor_cls WindowsExecutordef execute(param):# 执行用户代码is_timeout, stdout executor_cls(param).execute()if is_timeout:# 执行超时了return {is_timeout: is_timeout,done: True,output: stdout,}else:arr stdout.split(InputRequestException)if len(arr) 1:# 需要用户输入return {is_timeout: is_timeout,done: False,event: {type: input_request,prompt: arr[-1]}}else:# 正常执行结束return {is_timeout: is_timeout,done: True,output: stdout,}子进程需要执行的代码 import json import sysinput_queue []class InputRequestException(Exception):抛出此异常表示需要用户输入passdef execute(param):# 重写 input 函数__builtins__.input input_wrapper# input_queueglobal input_queueinput_queue param[input_queue]try:# 执行代码exec(param[code])except InputRequestException as e:# 如果需要用户输入则直接退出sys.stdout.write(\n InputRequestException e.args[0])exit()def input_wrapper(prompt):# 从 input_queue 中弹出if input_queue:input_str input_queue.pop(0)sys.stdout.write(str(prompt) input_str \n)return input_str# 需要用户输入raise InputRequestException(str(prompt))if __name__ __main__:# 从标准输入读取 json 参数code、input_queuearg sys.stdin.read()# 执行execute(json.loads(arg))代码仓库 online-python-code-executor/queue-base (github.com) 参考 https://pythontutor.comhttps://github.com/seamile/PyTutor
http://www.zqtcl.cn/news/893504/

相关文章:

  • 网站开发与建设网站程序基础
  • 网站建设属于什么税php网站建设全程实例
  • 做网站语言排名2018淄博市沂源县建设局网站
  • 腾冲网站建设哪个电商平台最好
  • 重点实验室网站建设宁波seo优化服务
  • 怎么用手机做刷会员网站网页设计指什么
  • 小企业网站建设多少钱网页设计图片剧中
  • 新乐做网站优化如何做二级域名子目录网站
  • 如何在网站上做推广中国在数码网站注册域名好 gt
  • 电子商务电商网站饿建设管理网站建设
  • php网站出现乱码网站建设项目总结
  • 网站建设公司墨子网络用我在线网站建设
  • 长寿网站建设公司服装设计有哪些网站
  • 苍溪规划和建设局网站网页设计制作报告
  • html5网站 源码360浏览器个别网页打不开怎么解决
  • 找个小网站建设网站优点
  • 台州网站建设优化网站建设加微信
  • 公司网站建设费会计分录义乌商城集团的网站建设
  • 彩票网站建设基本流程网站文章页做百度小程序
  • 在淘宝上做代销哪个网站好推广普通话喜迎二十大的手抄报怎么画
  • 知名网站建设开发受欢迎的唐山网站建设
  • 普洱网站搭建创建论坛网站需要多少钱
  • 自己做的网站如何在网络上展示wordpress 手动采集
  • 上海做网站要多少钱wordpress教程app
  • 房地产设计网站沈阳人流哪个医院好安全
  • 贵阳专业做网站微信小程序商城源代码
  • seo建站收费地震郑州做网站开发销售
  • 东莞整站优化推广公司找火速建设企业网站要多少钱
  • 网站备案 两个域名东莞保安公司联系电话
  • 网站专业制作公司律师如何在网上推广