def task_run_loop_with_monitor(): from autoelective.parser import load_course_csv from autoelective.loop import main as run_main_loop from autoelective.monitor import main as run_monitor from autoelective.logger import ConsoleLogger from autoelective.const import SIGNAL_KILL_ALL_PROCESSES from autoelective.compat import install_ctrl_c_handler cout = ConsoleLogger("main") signals = Queue() with Manager() as manager: # shared objects goals = manager.list(load_course_csv()) ignored = manager.list() status = manager.dict() status["loop"] = 0 pList = [ Process(target=run_main_loop, args=(signals, goals, ignored, status), name="Loop"), Process(target=run_monitor, args=(signals, goals, ignored, status), name="Monitor"), ] for p in pList: p.daemon = True p.start() install_ctrl_c_handler() while True: signal = signals.get() time.sleep(0.1) # Wait a minute if signal == SIGNAL_KILL_ALL_PROCESSES: for p in pList: if p.is_alive(): p.terminate() cout.info("Process %s is killed" % p.name) break
def task_run_loop(): from autoelective.loop import main as run_main_loop from autoelective.logger import ConsoleLogger from autoelective.const import SIGNAL_KILL_ALL_PROCESSES cout = ConsoleLogger("main") signals = Queue() p = Process(target=run_main_loop, name="Main", args=(signals, )) p.daemon = True p.start() while True: try: signal = signals.get() # block process except KeyboardInterrupt as e: cout.info("Process %s is killed" % os.getpid()) return time.sleep(0.1) # wait a minute if signal == SIGNAL_KILL_ALL_PROCESSES: if p.is_alive(): p.terminate() cout.info("Process %s is killed" % p.name) break
def task_run_loop_with_monitor(): from autoelective.parser import load_course_csv from autoelective.loop import main as run_main_loop from autoelective.monitor import main as run_monitor from autoelective.logger import ConsoleLogger from autoelective.const import SIGNAL_KILL_ALL_PROCESSES cout = ConsoleLogger("main") signals = Queue() with Manager() as manager: # shared objects goals = manager.list(load_course_csv()) ignored = manager.list() status = manager.dict() status["main_loop"] = 0 status["login_loop"] = 0 status["error_count"] = 0 status["errors"] = manager.dict() pList = [ Process(target=run_main_loop, name="Main", args=(signals, goals, ignored, status)), Process(target=run_monitor, name="Monitor", args=(signals, goals, ignored, status)), ] for p in pList: p.daemon = True p.start() while True: try: signal = signals.get() # block process except KeyboardInterrupt as e: cout.info("Process %s is killed" % os.getpid()) return time.sleep(0.1) # wait a minute if signal == SIGNAL_KILL_ALL_PROCESSES: for p in pList: if p.is_alive(): p.terminate() cout.info("Process %s is killed" % p.name) break
def task_run_loop(userInfo): config = AutoElectiveConfig() # create singleton first cout = ConsoleLogger("main") signals = Queue() p = Process(target=run_main_loop, name="Main", args=(signals, userInfo)) p.daemon = True p.start() while True: try: signal = signals.get() # block process except KeyboardInterrupt as e: cout.info("Process %s is killed" % os.getpid()) return time.sleep(0.1) # wait a minute if signal == SIGNAL_KILL_ALL_PROCESSES: if p.is_alive(): p.terminate() cout.info("Process %s is killed" % p.name) break
from autoelective.elective import ElectiveClient from autoelective.captcha import CaptchaRecognizer from autoelective.course import Course from autoelective.config import generalCfg from autoelective.parser import load_course_csv, get_tables, get_courses, get_courses_with_detail from autoelective.logger import ConsoleLogger, FileLogger from autoelective.exceptions import InvalidTokenError, InvalidSessionError, ServerError,\ StatusCodeError, NotInCoursePlanException, SystemException, CaughtCheatingError,\ ConflictingTimeError, RepeatedElectionError, OperationTimedOutError, ElectivePermissionError,\ ElectionSuccess, ElectionFailedError, CreditLimitedError iaaa = IAAAClient() elective = ElectiveClient() recognizer = CaptchaRecognizer() cout = ConsoleLogger("main") ferr = FileLogger("main.error") # main 的子日志,同步输出到 console interval = generalCfg.getint("client", "Refresh_Interval") deviation = generalCfg.getfloat("client", "Refresh_Interval_Random_Deviation") def get_refresh_interval(): if deviation <= 0: return interval else: delta = (random.random() * 2 - 1) * deviation * interval return interval + delta def get_concise_course(course):