import time import os from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor def zhibo(): os.system("scrapy crawl zhibo") def roll_ball(): os.system("scrapy crawl roll_lanqiu") os.system("scrapy crawl roll_wangqiu") os.system("scrapy crawl roll_bangqiu") os.system("scrapy crawl roll_zuqiu") os.system("scrapy crawl jieshu") def ball(): os.system("scrapy crawl lanqiu") os.system("scrapy crawl bangqiu") os.system("scrapy crawl wangqiu") os.system("scrapy crawl zuqiu") def other(): os.system("scrapy crawl guanjun") os.system("scrapy crawl saiguo") def kill_ball(): os.system("ps -ef | grep scrapy | grep -v grep | cut -c 9-15 | xargs kill -9") if __name__ == "__main__": executors = { 'default': ThreadPoolExecutor(20), 'processpool': ProcessPoolExecutor(5) } scheduler = BackgroundScheduler(executors=executors) # 每20分钟执行一次 scheduler.add_job(zhibo, 'interval', seconds=5) scheduler.add_job(roll_ball, 'interval', seconds=30) scheduler.add_job(ball, 'interval', minutes=3) scheduler.add_job(other, 'interval', minutes=30) scheduler.add_job(kill_ball, 'interval', minutes=150) scheduler.start() print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: while True: time.sleep(2) except (KeyboardInterrupt, SystemExit): scheduler.shutdown()