diff --git a/hikyuu/gui/data/UsePytdxImportToH5Thread.py b/hikyuu/gui/data/UsePytdxImportToH5Thread.py index 8d60ac6c0..e4ddfb5eb 100644 --- a/hikyuu/gui/data/UsePytdxImportToH5Thread.py +++ b/hikyuu/gui/data/UsePytdxImportToH5Thread.py @@ -49,6 +49,7 @@ class UsePytdxImportToH5Thread(QThread): def __init__(self, parent, config): super(self.__class__, self).__init__() self.parent = parent + self.log_queue = parent.mp_log_q if parent is not None else None self.config = config self.msg_name = 'HDF5_IMPORT' @@ -79,7 +80,7 @@ def init_task(self): self.tasks = [] if self.config.getboolean('weight', 'enable', fallback=False): - self.tasks.append(ImportWeightToSqliteTask(self.parent.mp_log_q, self.queue, self.config, dest_dir)) + self.tasks.append(ImportWeightToSqliteTask(self.log_queue, self.queue, self.config, dest_dir)) #if self.config.getboolean('finance', 'enable', fallback=False): # self.tasks.append(ImportHistoryFinanceTask(self.queue, dest_dir)) @@ -128,14 +129,14 @@ def init_task(self): trans_max_days = (today - trans_start_date).days + 1 self.tasks.append( ImportPytdxTransToH5( - self.parent.mp_log_q, self.queue, sqlite_file_name, 'SH', self.quotations, use_hosts[cur_host][0], + self.log_queue, self.queue, sqlite_file_name, 'SH', self.quotations, use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, trans_max_days ) ) cur_host += 1 self.tasks.append( ImportPytdxTransToH5( - self.parent.mp_log_q, self.queue, sqlite_file_name, 'SZ', self.quotations, use_hosts[cur_host][0], + self.log_queue, self.queue, sqlite_file_name, 'SZ', self.quotations, use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, trans_max_days ) ) @@ -145,16 +146,16 @@ def init_task(self): start_date = datetime.datetime.strptime(config['ktype']['min_start_date'], '%Y-%m-%d').date() self.tasks.append( ImportPytdxToH5( - self.parent.mp_log_q, self.queue, self.config, 'SH', '1MIN', self.quotations, - use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, + self.log_queue, self.queue, self.config, 'SH', '1MIN', self.quotations, use_hosts[cur_host][0], + use_hosts[cur_host][1], dest_dir, start_date.year * 100000000 + start_date.month * 1000000 + start_date.day * 10000 ) ) cur_host += 1 self.tasks.append( ImportPytdxToH5( - self.parent.mp_log_q, self.queue, self.config, 'SZ', '1MIN', self.quotations, - use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, + self.log_queue, self.queue, self.config, 'SZ', '1MIN', self.quotations, use_hosts[cur_host][0], + use_hosts[cur_host][1], dest_dir, start_date.year * 100000000 + start_date.month * 1000000 + start_date.day * 10000 ) ) @@ -166,14 +167,14 @@ def init_task(self): time_max_days = (today - time_start_date).days + 1 self.tasks.append( ImportPytdxTimeToH5( - self.parent.mp_log_q, self.queue, sqlite_file_name, 'SH', self.quotations, use_hosts[cur_host][0], + self.log_queue, self.queue, sqlite_file_name, 'SH', self.quotations, use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, time_max_days ) ) cur_host += 1 self.tasks.append( ImportPytdxTimeToH5( - self.parent.mp_log_q, self.queue, sqlite_file_name, 'SZ', self.quotations, use_hosts[cur_host][0], + self.log_queue, self.queue, sqlite_file_name, 'SZ', self.quotations, use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, time_max_days ) ) @@ -183,16 +184,16 @@ def init_task(self): start_date = datetime.datetime.strptime(config['ktype']['min5_start_date'], '%Y-%m-%d').date() self.tasks.append( ImportPytdxToH5( - self.parent.mp_log_q, self.queue, self.config, 'SH', '5MIN', self.quotations, - use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, + self.log_queue, self.queue, self.config, 'SH', '5MIN', self.quotations, use_hosts[cur_host][0], + use_hosts[cur_host][1], dest_dir, start_date.year * 100000000 + start_date.month * 1000000 + start_date.day * 10000 ) ) cur_host += 1 self.tasks.append( ImportPytdxToH5( - self.parent.mp_log_q, self.queue, self.config, 'SZ', '5MIN', self.quotations, - use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, + self.log_queue, self.queue, self.config, 'SZ', '5MIN', self.quotations, use_hosts[cur_host][0], + use_hosts[cur_host][1], dest_dir, start_date.year * 100000000 + start_date.month * 1000000 + start_date.day * 10000 ) ) @@ -202,7 +203,7 @@ def init_task(self): start_date = datetime.datetime.strptime(config['ktype']['day_start_date'], '%Y-%m-%d').date() self.tasks.append( ImportPytdxToH5( - self.parent.mp_log_q, self.queue, self.config, 'SH', 'DAY', self.quotations, use_hosts[cur_host][0], + self.log_queue, self.queue, self.config, 'SH', 'DAY', self.quotations, use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, start_date.year * 100000000 + start_date.month * 1000000 + start_date.day * 10000 ) @@ -210,7 +211,7 @@ def init_task(self): cur_host += 1 self.tasks.append( ImportPytdxToH5( - self.parent.mp_log_q, self.queue, self.config, 'SZ', 'DAY', self.quotations, use_hosts[cur_host][0], + self.log_queue, self.queue, self.config, 'SZ', 'DAY', self.quotations, use_hosts[cur_host][0], use_hosts[cur_host][1], dest_dir, start_date.year * 100000000 + start_date.month * 1000000 + start_date.day * 10000 ) diff --git a/hikyuu/gui/data/UseTdxImportToH5Thread.py b/hikyuu/gui/data/UseTdxImportToH5Thread.py index 9bb335818..cdef5b883 100644 --- a/hikyuu/gui/data/UseTdxImportToH5Thread.py +++ b/hikyuu/gui/data/UseTdxImportToH5Thread.py @@ -41,6 +41,7 @@ def __init__(self, parent, config): super(self.__class__, self).__init__() self.logger = logging.getLogger(self.__class__.__name__) self.parent = parent + self.log_queue = parent.mq_log_q if parent is not None else None self.config = config self.msg_name = 'HDF5_IMPORT' @@ -66,39 +67,27 @@ def __init__(self, parent, config): self.queue = Queue() self.tasks = [] if self.config.getboolean('weight', 'enable', fallback=False): - self.tasks.append(ImportWeightToSqliteTask(self.parent.mp_log_q, self.queue, self.config, dest_dir)) + self.tasks.append(ImportWeightToSqliteTask(self.log_queue, self.queue, self.config, dest_dir)) if self.config.getboolean('ktype', 'day', fallback=False): self.tasks.append( - ImportTdxToH5Task( - self.parent.mp_log_q, self.queue, config, 'SH', 'DAY', self.quotations, src_dir, dest_dir - ) + ImportTdxToH5Task(self.log_queue, self.queue, config, 'SH', 'DAY', self.quotations, src_dir, dest_dir) ) self.tasks.append( - ImportTdxToH5Task( - self.parent.mp_log_q, self.queue, config, 'SZ', 'DAY', self.quotations, src_dir, dest_dir - ) + ImportTdxToH5Task(self.log_queue, self.queue, config, 'SZ', 'DAY', self.quotations, src_dir, dest_dir) ) if self.config.getboolean('ktype', 'min5', fallback=False): self.tasks.append( - ImportTdxToH5Task( - self.parent.mp_log_q, self.queue, config, 'SH', '5MIN', self.quotations, src_dir, dest_dir - ) + ImportTdxToH5Task(self.log_queue, self.queue, config, 'SH', '5MIN', self.quotations, src_dir, dest_dir) ) self.tasks.append( - ImportTdxToH5Task( - self.parent.mp_log_q, self.queue, config, 'SZ', '5MIN', self.quotations, src_dir, dest_dir - ) + ImportTdxToH5Task(self.log_queue, self.queue, config, 'SZ', '5MIN', self.quotations, src_dir, dest_dir) ) if self.config.getboolean('ktype', 'min', fallback=False): self.tasks.append( - ImportTdxToH5Task( - self.parent.mp_log_q, self.queue, config, 'SH', '1MIN', self.quotations, src_dir, dest_dir - ) + ImportTdxToH5Task(self.log_queue, self.queue, config, 'SH', '1MIN', self.quotations, src_dir, dest_dir) ) self.tasks.append( - ImportTdxToH5Task( - self.parent.mp_log_q, self.queue, config, 'SZ', '1MIN', self.quotations, src_dir, dest_dir - ) + ImportTdxToH5Task(self.log_queue, self.queue, config, 'SZ', '1MIN', self.quotations, src_dir, dest_dir) ) def __del__(self): diff --git a/hikyuu/gui/importdata.py b/hikyuu/gui/importdata.py index 9c89cf04b..52428e517 100644 --- a/hikyuu/gui/importdata.py +++ b/hikyuu/gui/importdata.py @@ -27,7 +27,7 @@ def getCurrentConfig(self): #读取保存的配置文件信息,如果不存在,则使用默认配置 this_dir = self.getUserConfigDir() import_config = ConfigParser() - import_config.read(this_dir + '/importdata-gui.ini', encoding = 'utf-8') + import_config.read(this_dir + '/importdata-gui.ini', encoding='utf-8') return import_config def initThreads(self): @@ -35,14 +35,16 @@ def initThreads(self): self.hdf5_import_thread = None self.mysql_import_thread = None self.import_running = False - self.progress = {'DAY': 0, '1MIN': 0, '5MIN': 0, 'TRANS':0, 'TIME':0} - self.info_type = {'DAY': '日线数据', '1MIN': '一分钟线', '5MIN': '五分钟线', 'TRANS':'历史分笔', 'TIME':'分时数据'} + self.progress = {'DAY': 0, '1MIN': 0, '5MIN': 0, 'TRANS': 0, 'TIME': 0} + self.info_type = {'DAY': '日线数据', '1MIN': '一分钟线', '5MIN': '五分钟线', 'TRANS': '历史分笔', 'TIME': '分时数据'} self.escape_time = 0.0 self.details = [] def print_progress(self, ktype, progress): if progress != self.progress[ktype]: - print('import progress: {}% - {} - 已耗时 {:>.2f} 分钟'.format(progress, self.info_type[ktype], self.escape_time)) + print( + 'import progress: {}% - {} - 已耗时 {:>.2f} 分钟'.format(progress, self.info_type[ktype], self.escape_time) + ) self.progress[ktype] = progress def on_message_from_thread(self, msg): @@ -53,7 +55,7 @@ def on_message_from_thread(self, msg): msg_name, msg_task_name = msg[:2] if msg_name == 'ESCAPE_TIME': self.escape_time = msg_task_name / 60 - + elif msg_name == 'HDF5_IMPORT': if msg_task_name == 'INFO': print(msg[2]) @@ -108,7 +110,6 @@ def on_message_from_thread(self, msg): else: print('权息{}'.format(msg[2])) - def start_import_data(self): config = self.getCurrentConfig() dest_dir = config.get('hdf5', 'dir') @@ -130,9 +131,9 @@ def start_import_data(self): QCoreApplication.processEvents() if config.getboolean('tdx', 'enable'): - self.hdf5_import_thread = UseTdxImportToH5Thread(config) + self.hdf5_import_thread = UseTdxImportToH5Thread(None, config) else: - self.hdf5_import_thread = UsePytdxImportToH5Thread(config) + self.hdf5_import_thread = UsePytdxImportToH5Thread(None, config) self.hdf5_import_thread.message.connect(self.on_message_from_thread) self.hdf5_import_thread.start() @@ -150,5 +151,5 @@ def main(): sys.exit(app.exec()) -if __name__ == '__main__': +if __name__ == '__main__': main() diff --git a/hikyuu/util/mylog.py b/hikyuu/util/mylog.py index 035e24b7d..76a7f5cfa 100644 --- a/hikyuu/util/mylog.py +++ b/hikyuu/util/mylog.py @@ -182,6 +182,8 @@ def capture_multiprocess_all_logger(queue, level): @param multiprocessing.Queue queue 指定的 mp Queue @param level 日志输出等级 """ + if queue is None: + return qh = logging.handlers.QueueHandler(queue) level = get_default_logger().level for name in logging.Logger.manager.loggerDict.keys():