如何在python中运行本地服务器的多个实例
我下载了网站的离线zim档案,如如何在python中运行本地服务器的多个实例,python,python-3.x,Python,Python 3.x,我下载了网站的离线zim档案,如wikipedia.com,stackoverflow.com,unix.stackexchange.com等,并通过下面的脚本为它们提供服务 #!/usr/bin/env python3 import os import subprocess import sys import threading from zimply import ZIMServer ZIMServer("/home/user/zim/wikipedia_en_all_novid_2018
wikipedia.com
,stackoverflow.com
,unix.stackexchange.com
等,并通过下面的脚本为它们提供服务
#!/usr/bin/env python3
import os
import subprocess
import sys
import threading
from zimply import ZIMServer
ZIMServer("/home/user/zim/wikipedia_en_all_novid_2018-05.zim", index_file="/home/user/zim/wikipedia_en_all_novid_2018-05.idx", port=8790, encoding="utf-8")
它运行良好,但当我添加另一行时
ZIMServer("/home/user/zim/math.stackexchange.com_eng_all_2018-08.zim", index_file="/home/user/zim/math.stackexchange.com_eng_all_2018-08.idx", port=7890, encoding="utf-8")
它不会加载第二个ZIMServer
。我认为这是一个python多线程问题。如何在单个脚本中同时运行这两个脚本?使用,再加上端口增量
from multiprocessing import Process
import os
import subprocess
import sys
import threading
from zimply import ZIMServer
def f(port, file, idx):
ZIMServer(file, index_file=idx, port=port, encoding="utf-8")
if __name__ == '__main__':
p1 = Process(target=f, args=(8790,"/home/user/zim/wikipedia_en_all_novid_2018-05.zim",""))
p2 = Process(target=f, args=(8791,"/home/user/zim/whatever.zim",""))
p1.start()
p2.start()
谢谢你的回答。我需要添加
ZIMServer(“/home/user/zim/math.stackexchange.com_eng_all_2018-08.zim”,index_file=“/home/user/zim/math.stackexchange.com_eng_all_2018-08.idx”,port=7890,encoding=“utf-8”)
,我需要添加另一个def(port):ZIMServer(/home/user/zim/math.stackexchange.com_eng_all_all_2018-08.zim),index_文件吗=“/home/user/zim/math.stackexchange.com_eng_all_2018-08.idx”,port=8090,encoding=“utf-8”)
formath.stackexchange.com
?实际上您不能修改函数并将其作为参数传递。等等,我会这样做。编辑我的答案,用“/home/user/zim/math.stackexchange.com_eng_all_all_2018-08.zim”替换“where”