forked from aa342138039/JD-SHOPPER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunserver.py
executable file
·48 lines (41 loc) · 1.31 KB
/
runserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Depend
from Config import config
from Core import core
from Logger import logger
from Scheduler import Scheduler
from Server import server
from threading import Thread
from GUI.gui import gui
from concurrent.futures import ProcessPoolExecutor
PROCESS_MODE = config.Server.process_mode
SCHEDULER = config.Scheduler.open
SERVER = config.Server.open
GUI = config.GUI.open
def running():
if not SCHEDULER:
thread_core = Thread(target=core)
thread_core.start()
else: # 调度器开启后core函数将被scheduler调度器代理,开启定时执行core
startTime = config.Scheduler.time
skipWeekend = config.Scheduler.skip_weekend
scheduler = Scheduler(task=core, startTime=startTime, skipWeekend=skipWeekend)
if SERVER:
if PROCESS_MODE:
work_count = config.Server.process_count
server_process(work_count)
else:
thread_server = Thread(target=server)
thread_server.start()
if GUI:
gui()
def server_process(work_count=4):
with ProcessPoolExecutor(work_count) as pool:
for i in range(work_count):
pool.submit(server())
if __name__ == "__main__":
DEBUG = config.Debug.open
if DEBUG:
logger.info("\n===== DEBUG MODE =====")
core()
else:
running()