在浏览器中安全地为多个独立的终端会话提供服务
runthis-server的Python项目详细描述
运行此服务器
运行此服务器是一个通过HTTP提供唯一的交互式终端会话的工具。 这为各种 命令行应用程序。在
安装
运行此服务器可以与conda或pip一起安装:
# use the conda-forge channel $ conda install -c conda-forge runthis-server # Or you can use Pip, if you must. $ pip install runthis-server
测试用途
您可以使用runthis-server
命令行实用程序启动服务器。在
生产用途
对于生产,我们建议使用 ^{这里是服务器1} 夸脱的申请。要同时使用RunThis Server+hypercorn,请运行 以下命令:
$ hypercorn runthis.server.hypercorn:app
或者,如果需要使用HTTPS证书运行:
$ hypercorn runthis.server.hypercorn:app \ --certfile /pat/to/certs/fullchain.pem \ --keyfile /path/to/certs/privkey.pem \ --bind 0.0.0.0:80
注意:当前无法将配置文件的路径传递到
在hypercorn下运行时运行此服务器。服务器只会查找
当前工作目录中的runthis-server.yml
文件,并使用该文件。
如果该文件不存在,则使用默认值!拜托
将目录改为前面的runthis-server.yml
文件的位置
跑得很漂亮。在
配置
默认情况下,服务器配置为通过查找runthis-server.yml
文件来运行
在当前工作目录中。您可以使用
--config
标志。在
所有配置变量都是可选的。下面列出了它的含义 默认值。通常,这些在YAML文件中显示为顶级键:
# The path to the public certificate file. This is currently only# used by the hypercorn interface, and is passed directly though# to hypercorn's configuration.certfile:None# The command variable is a string that lists ths command, or path# to run whenever a new instance is requested. Nominally, this is# a command that starts a REPL, but doesn't have to be.command:"python3"# The docker variable is a boolean that determines whether or not# the command should be run in its own single-use docker container.# Docker, of course, must be available on the host.docker:true# The docker_image varible specifies which docker image should be# started up if the command is being run in a docker container.docker_image:"ubuntu:latest"# The host variable is the URL or IP address that the server is# running on. By default, this is "127.0.0.1". Other valid options are# "0.0.0.0", which will expose the server to the outside world, as well# as any valid CNAME or IP address. RunThis Server works by taking in# a request and then redirecting to a new port on this server. The selection# of the host determines the redirection address. Here is the mapping:## host -> TTY redirect_base# 127.0.0.1 -> 0.0.0.0# 0.0.0.0 -> IP address of server as seen by https://api.ipify.org# IP or CNAME -> Same IP or CNAMEhost:"127.0.0.1"# The path to the private certificate file. This is currently only# used by the hypercorn interface, and is passed directly though# to hypercorn's configuration.certfile:None# The port variable is an int that specifies the port number that the# the RunThis Server itself operates on. The TTY redirects go to# separate ports. Therefore you would access the RunThis Server as f"http://{host}:{port}"port:5000# The tty_server variable is a string flag that represents the TTY server software that# will be executed each time a request is made. Currently, the valid options are:## gotty: go-based TTY server https://github.com/yudai/gotty# ttyd: C++ TTY server https://tsl0922.github.io/ttyd/tty_server:"gotty"# The gotty_path is the path to the gotty executablegotty_path:"gotty"# The ttyd_path is the path to the ttyd executablettyd_path:"ttyd"# The tty_server_port_start variable is an integer at which the TTY servers# will start serving their terminals. Each successive request increases this# value by one, so that each session recieves its own unique value.tty_server_port_start:8080
上述值也可以嵌入顶层runthis
键中,
如果需要与其他文件兼容。对埃克斯梅普来说
runthis:host:0.0.0.0port:80
请求参数
服务器的请求被发送到URL f"http://{host}:{port}"
。
但是,这个URL接受GET或POST请求并接受take
以下参数作为选项。在
presetup:这是初始化新解释器会话的代码。 它在不通知用户的情况下执行。在
setup:这是在解释器启动时立即执行的代码 向上,在执行预设代码后。另外,这段代码也会得到响应 (以其源格式打印)在执行之前发送给用户。这是 很适合运行示例。在
例如,下面的GET请求将静默运行import sys
,然后
在逐字打印"print(sys.executable)"
之后执行print(sys.executable)
。在
http://127.0.0.1:5000/?presetup=import+sys&setup=print%28sys.executable%29
通常,您应该有一个URL编码库从中生成这些URL 你的源代码。在
- 项目
标签: