如何让两个不同的python脚本在同一个端口上运行?

时间:2021-12-28 20:41:39

Currently I'm developing web services in python using web.py, that serves different functions. Something like

目前我正在使用web在python中开发web服务。py,服务于不同的函数。类似的

BigQueryService.py
LogicImplementer.py
PostgreService.py

Each service works perfectly when running on the local machine. After deploying on the server, due to I'm refering an other python script, it returns a module error.

在本地机器上运行时,每个服务都可以完美地工作。在服务器上部署之后,由于我引用了另一个python脚本,它返回一个模块错误。

Since we have to run all the services on the same port, I pasted all the scripts into a single file named Engine and made it to work using the command

由于我们必须在同一个端口上运行所有的服务,所以我将所有脚本粘贴到一个名为Engine的文件中,并使其使用该命令工作

$ nohup python Engine.py 8080 &

美元nohup python引擎。py 8080 &

Is there any better way to structure the service in web.py? Or is there a way to run all the individual scripts on the same port?

有更好的方法在web.py中构造服务吗?还是有办法在同一个端口上运行所有的脚本?

1 个解决方案

#1


2  

If each service creates its own listener/server socket on the port, then the answer is no. You will need to use the equivalent of an app server that has a single server port and distributes the incoming request to the relevant app (running on the server) based typically on the relative path - so e.g. http://myserver.net:8080/bqs paths get passed to your BiqQueryService, /li to LinkImplementor, /pgs to PostgreService. Flask will do something like this, I'm sure other web service frameworks will too. The server will handle all the communication stuff, pass requests to the app (e.g. bqs) and handle sending response to the client.

如果每个服务在端口上创建自己的侦听器/服务器套接字,那么答案是no。您将需要使用的应用程序服务器都有一个单独的服务器端口,并且将传入请求分发给相关的应用程序服务器)上运行(通常基于相对路径,所以如http://myserver.net:8080 / bqs路径传递给你的BiqQueryService,PostgreService /李LinkImplementor,后卫。Flask也会这样做,我相信其他的web服务框架也会这样做。服务器将处理所有通信内容,将请求传递给应用程序(例如bqs),并处理向客户端发送响应。

#1


2  

If each service creates its own listener/server socket on the port, then the answer is no. You will need to use the equivalent of an app server that has a single server port and distributes the incoming request to the relevant app (running on the server) based typically on the relative path - so e.g. http://myserver.net:8080/bqs paths get passed to your BiqQueryService, /li to LinkImplementor, /pgs to PostgreService. Flask will do something like this, I'm sure other web service frameworks will too. The server will handle all the communication stuff, pass requests to the app (e.g. bqs) and handle sending response to the client.

如果每个服务在端口上创建自己的侦听器/服务器套接字,那么答案是no。您将需要使用的应用程序服务器都有一个单独的服务器端口,并且将传入请求分发给相关的应用程序服务器)上运行(通常基于相对路径,所以如http://myserver.net:8080 / bqs路径传递给你的BiqQueryService,PostgreService /李LinkImplementor,后卫。Flask也会这样做,我相信其他的web服务框架也会这样做。服务器将处理所有通信内容,将请求传递给应用程序(例如bqs),并处理向客户端发送响应。