Skip to content

Commit b9b6f9b

Browse files
committed
Add: host与port参数传入
1 parent 9b03ef8 commit b9b6f9b

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

__pycache__/test1.cpython-38.pyc

-251 Bytes
Binary file not shown.

start.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
port = 24813
21
timeout = 1800 # 超过此时长游戏未继续进行则删除游戏进程,单位s
32
###############################################################################################
4-
version = 1.2
3+
version = 1.3
54
###############################################################################################
65
import os
6+
import argparse
77
import time
88
import json
99
import threading
@@ -143,7 +143,24 @@ def run(self):
143143
time_check = TimeCheck()
144144
time_check.start()
145145

146-
host = ("127.0.0.1", port)
147-
print(f"listen at port {port}")
146+
parser = argparse.ArgumentParser(description="Start script with port and host")
147+
parser.add_argument(
148+
"-H", "--host", type=str, help="Host address", default="0.0.0.0"
149+
)
150+
parser.add_argument("-p", "--port", type=int, help="Port number", default=24813)
151+
args = parser.parse_args()
152+
host = args.host
153+
port = args.port
154+
155+
host = (host, port)
156+
157+
print(f"Douzero_API has been launched successfully.")
158+
print(f"Server listening on {host[0]}:{port}.")
159+
148160
server = HTTPServer(host, Request)
149-
server.serve_forever() # 开启服务
161+
try:
162+
server.serve_forever() # 开启服务
163+
except KeyboardInterrupt:
164+
server.server_close()
165+
print("Server closed.")
166+
exit(0)

0 commit comments

Comments
 (0)