在浏览器中安全地为多个独立的终端会话提供服务

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命令行实用程序启动服务器。在

^{pr2}$

生产用途

对于生产,我们建议使用 ^{这里是服务器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 你的源代码。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java初学者Swing递归   java将hashmap转换为JSON字符串   cURL和java字符串变量出错   java为什么不将其视为多重继承,而所有类都首先从对象类扩展,然后再扩展其他类   java如何在eclipse中添加插件依赖项   使用java从Ms word表中提取图片   java实现可比较的接口   验证生成的事务时发生java错误。木栓   java@OneToMany和不同的主键   java Jaxb2在相对路径上找不到xsd架构   java客户端C++服务器数据发送/接收问题   javajaxws-webservice。改变节点结构   java如何将带有特殊字符的字符串转换为另一个转义字符串   netbeans如何链接JGraph传感器和Java邮件?   java如何在单个tomcat中检查每个web应用程序的内存大小?   客户端图形QLJava类生成器