from multiprocessing import Pool, RLock, freeze_support,Queue,Pipe import multiprocessing import functools import datetime from time import sleep from tqdm import tqdm from TS_logs import TS_log_info from TS_util import ( TS_util_get_tradelist, TS_util_get_real_date, TS_util_get_next_datetime, TS_util_get_now_time, TS_util_date_convert, trade_date_sse )
deflog_c(child_conn,codelist,n): for trade_date in codelist[n::8][0:17]: msg = '{} #Job{} trade date {}.' \ .format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),n,trade_date) child_conn.send(msg) print('workers exit')
L = list(range(8))
if __name__ == '__main__': freeze_support() # for Windows support parent_conn,child_conn = Pipe() tqdm.set_lock(RLock()) codelist = trade_date_sse func = functools.partial(log_c,child_conn,codelist) p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) p.map(func, L) while parent_conn.poll(0.001): print(parent_conn.recv()) p.close() p.join() parent_conn.close() child_conn.close()