将Python程序通过spawn-fcgi转换为模块

我们已经有许多以spawn-fcgi启动的Python脚本编写的旧服务,通过如下所示的脚本进行pipe理:

 exec setuidgid www pgrphack \ argv0 spawn-fcgi my_server \ -p "$PORT" \ -F "$CONCURRENCY" -- \ "$MY_ROOT"/bin/my_server_backend 

my_server_backend是一个Python脚本,如下所示:

 #!/usr/bin/env python import socket import json from my_processor import get_results def main(): s = socket.fromfd(sys.stdin.fileno(), socket.AF_INET, socket.SOCK_STREAM) while True: client, _ = s.accept() request_id, results = get_results(client) res_json = json.dumps(results) response = '%s %d %s' % (request_id, len(res_json), res_json) try: client.sendall(response) finally: client.close() if __name__ == '__main__': main() 

我需要将脚本转换为Python模块。 但是,如果我这样做,并更改spawn-fcgi脚本

 exec setuidgid www pgrphack \ argv0 spawn-fcgi my_server \ -p "$PORT" \ -F "$CONCURRENCY" -- \ python -m backends.server 

我明白了

 spawn-fcgi: exec failed: No such file or directory spawn-fcgi: child exited with: 2 spawn-fcgi: exec failed: No such file or directory spawn-fcgi: child exited with: 2 spawn-fcgi: exec failed: No such file or directory spawn-fcgi: child exited with: 2 spawn-fcgi: exec failed: No such file or directory spawn-fcgi: child exited with: 2 spawn-fcgi: exec failed: No such file or directory spawn-fcgi: child exited with: 2 

一遍又一遍的重复。 为什么这不起作用?