Python3.x:实现多任务(多进程)
# python3 # author lizm # datetime 2018-02-13 16:00:00 # -*- coding: utf-8 -*- #引用xyzq_shrgp 文件的doStartShrgp函数 from xyzq_shrgp import doStartShrgp from xyzq_shrjj import doStartShrjj from xyzq_szzjtj import doStartSzzjtj from datetime import datetime import datetime, time import sys import logging import configparser import threading logger = logging.getLogger() #set loghandler file = logging.FileHandler("yzzq_log"+time.strftime("%Y%m%d")+".log") logger.addHandler(file) #set formater formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s") file.setFormatter(formatter) #set log level logger.setLevel(logging.NOTSET) #调用xyzq_shrgp 文件的doStartShrgp函数 def doShrgp(date): doStartShrgp(date) def doShrjj(date): doStartShrjj(date) def doSzzjtj(date): doStartSzzjtj(date) #测试 if __name__ == '__main__': if len(sys.argv) < 2: logger.info("传递参数错误,日期参数[格式:20180122]") print("传递参数错误,日期参数[格式:20180122]") else: vrg_date = sys.argv[1] if len(vrg_date) ==8: #加载任务进程(注意:参数数以','结尾) th_shrgp = threading.Thread(target=doShrgp,args=(vrg_date,)) #加载任务进程(注意:参数以','结尾) th_shrjj = threading.Thread(target=doShrjj,args=(vrg_date,)) #加载任务进程(注意:参数以','结尾) th_szzjtj = threading.Thread(target=doSzzjtj,args=(vrg_date,)) #开始任务(并发执行) th_shrgp.start() th_shrjj.start() th_szzjtj.start() else: logger.info("日期参数格式不正确,请用格式:20180116") print("日期参数格式不正确,请用格式:20180116")
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/16768.html