def parseMroToCsvMP(): # 多进程消息回调函数 def callback(x): pid = current_process().pid pname = current_process().name print('{},{},{}'.format(pname, pid, x)) # 最大的进程数为 为 CPU的核心数. po = Pool(cpu_count()) print(u'CPU核心数为{},设置进程池最大进程数为:{}'.format(cpu_count(), cpu_count())) # xml文件夹路径 xmlPath = xmlConf.xmlPath # 保存csv文件夹路径 csvPathMro = xmlConf.csvPathMro # 获取xml文件列表 xmlFileListMro = getFileList(xmlPath, r'.+_MRO_.+\.xml') for xmlFileMro in xmlFileListMro: # result = parseXmlMro.toCSV(xmlFile,csvPath) # 解析xml,并保存为csv文件 # 多进程解析xml,并保存为csv文件 po.apply_async(parseXmlMro.toCSV, args=(xmlFileMro, csvPathMro), callback=callback) print("----start----") po.close() # 关闭进程池,关闭后po不再接受新的请求 po.join() # 等待po中的所有子进程执行完成,必须放在close语句之后 '''如果没有添加join(),会导致有的代码没有运行就已经结束了''' print("-----end-----")
def unzipMrFileMP(): # 最大的进程数为 为 CPU的核心数. po = Pool(cpu_count()) # 创建文件夹 unzipDirPath = os.path.abspath(unzipConf.xmlPath) if not os.path.exists(unzipDirPath): os.makedirs(unzipDirPath) # 获取压缩文件列表 zipFileList = getFileList(unzipConf.zipPath, r'\.') def callback(x): print(' {}'.format(current_process().name, x)) for zipFile in zipFileList: # 解压缩文件 # unzip.unzipFile(zipFile, unzipDirPath) po.apply_async(unzip.unzipFile, args=(zipFile, unzipDirPath), callback=callback) print("----start----") po.close() # 关闭进程池,关闭后po不再接受新的请求 po.join() # 等待po中的所有子进程执行完成,必须放在close语句之后 '''如果没有添加join(),会导致有的代码没有运行就已经结束了''' print("-----end-----")
def parseMreToCsvMP(): # 多进程消息回调函数 def callback(x): pid = current_process().pid pname = current_process().name print('{},{},{}'.format(pname, pid, x)) # 最大的进程数为 为 CPU的核心数. po = Pool(cpu_count()) print(u'CPU核心数为{},设置进程池最大进程数为:{}'.format(cpu_count(), cpu_count())) # 从配置文件导入xml文件夹路径 xmlPath = xmlConf.xmlPath # 从配置文件导入 保存csv文件夹路径 csvPathMre = xmlConf.csvPathMre xmlFileListMre = getFileList(xmlPath, r'.+_MRE_.+\.xml') for xmlFileMre in xmlFileListMre: '''每次循环将会用空闲出来的子进程去调用目标''' # parseXmlMre.toCSV(xmlFileMre,csvPathMre) po.apply_async(parseXmlMre.toCSV, args=(xmlFileMre, csvPathMre), callback=callback) print("----start----") po.close() # 关闭进程池,关闭后po不再接受新的请求 po.join() # 等待po中的所有子进程执行完成,必须放在close语句之后 '''如果没有添加join(),会导致有的代码没有运行就已经结束了''' print("-----end-----")
def main(): try: # 初始化数据库连接 conn, curs = dBConnect.connDb(dbConfig.usedDbType) #获取MRS样本文件 xmlFile = getFileList(dbConfig.xmlPath, r'.+_MRS_.+\.xml')[0] if curs: # 创建MRo的表 和 MRE的表 dBConnect.execSql(curs, dbConfig.MRO_15MI_Str_pg) dBConnect.execSql(curs, dbConfig.MRO_RIP_15MI_Str_pg) dBConnect.execSql(curs, dbConfig.MRE_15MI_Str_pg) curs.execute('commit;') # 获取 表头结构, 列名信息 titleList = readXML(xmlFile) # 创建MRS的表 createTable(titleList, curs, dbConfig.usedDbType) except Exception as e: print(e) finally: if conn: dBConnect.close(conn, curs)
def csvInDb(): # 初始化数据库连接 conn, curs = dbConnect.connDb(dbConf.usedDbType) # 获取csv文件列表 csvFileList = getFileList(dbConf.csvPath, r'.+\.csv') for csvFile in csvFileList: tableName, fileExtName = os.path.splitext(os.path.split(csvFile)[-1]) tableName = tableName.lower() try: if not conn: conn, curs = dbConnect.connDb(dbConf.usedDbType) # 检测表是否存在. # isExistTable = dbConnect.isTableExist(conn, curs, tableName, dbConf.usedDbType) # if not isExistTable: createTable.main() # 不存在就执行创建表的脚本 inDb.inDb(conn, curs, csvFile, tableName, dbConf.usedDbType) except Exception as e: print(str(e)) if conn: dbConnect.close(conn, curs)
if __name__ == '__main__': # 多进程消息回调函数 def callback(x): pid = current_process().pid pname = current_process().name print('{},{},{}'.format(pname, pid, x)) # 最大的进程数为 为 CPU的核心数. po = Pool(cpu_count()) print(u'CPU核心数为{},设置进程池最大进程数为:{}'.format(cpu_count(), cpu_count())) # 从配置文件导入xml文件夹路径 xmlPath = xmlConf.xmlPath # 从配置文件导入 保存csv文件夹路径 csvPathMrs = xmlConf.csvPathMrs xmlFileListMrs = getFileList(xmlPath, r'.+_MRS_.+\.xml') for xmlFileMrs in xmlFileListMrs: '''每次循环将会用空闲出来的子进程去调用目标''' # toCSV(xmlFileMrs, csvPathMrs) po.apply_async(toCSV, args=(xmlFileMrs, csvPathMrs), callback=callback) print("----start----") po.close() # 关闭进程池,关闭后po不再接受新的请求 po.join() # 等待po中的所有子进程执行完成,必须放在close语句之后 '''如果没有添加join(),会导致有的代码没有运行就已经结束了''' print("-----end-----")
# 包含弱覆盖, 过覆盖, 重叠覆盖分析,mod3干扰分析,方位角差异,PCI分析等. # 然后生成表导出 import os import numpy as np import pandas as pd from io import StringIO from multiprocessing import Pool, current_process from multiprocessing import cpu_count try: import dbConfig as dbConfig except ModuleNotFoundError: import db.dbConfig as dbConfig from getfile import getFileList try: import dbConnect as dbConnect except ModuleNotFoundError: import db.dbConnect as dbConnect try: import createTable as createTable except ModuleNotFoundError: import db.createTable as createTable if __name__ == '__main__': sqlFileList = getFileList(dbConfig.sqlPath, r'\.sql')
if __name__ == '__main__': # 多进程消息回调函数 def callback(x): pid = current_process().pid pname = current_process().name print('{},{},{}'.format(pname,pid,x)) # 最大的进程数为 为 CPU的核心数. po = Pool(cpu_count()) print(u'CPU核心数为{},设置进程池最大进程数为:{}'.format(cpu_count(),cpu_count())) # 从配置文件导入xml文件夹路径 xmlPath = xmlConf.xmlPath # 从配置文件导入 保存csv文件夹路径 csvPathMre = xmlConf.csvPathMre xmlFileListMre = getFileList(xmlPath,r'.+_MRE_.+\.xml') for xmlFileMre in xmlFileListMre: '''每次循环将会用空闲出来的子进程去调用目标''' # toCSV(xmlFileMre,csvPathMre) po.apply_async(toCSV, args=(xmlFileMre,csvPathMre), callback=callback) print("----start----") po.close() # 关闭进程池,关闭后po不再接受新的请求 po.join() # 等待po中的所有子进程执行完成,必须放在close语句之后 '''如果没有添加join(),会导致有的代码没有运行就已经结束了''' print("-----end-----")
# 多进程消息回调函数 def callback(x): pid = current_process().pid pname = current_process().name print('{},{},{}'.format(pname, pid, x)) # 最大的进程数为 为 CPU的核心数. po = Pool(cpu_count()) print(u'CPU核心数为{},设置进程池最大进程数为:{}'.format(cpu_count(), cpu_count())) # xml文件夹路径 xmlPath = xmlConf.xmlPath # 保存csv文件夹路径 csvPathMro = xmlConf.csvPathMro # 获取xml文件列表 xmlFileListMro = getFileList(xmlPath, r'.+_MRO_.+\.xml') for xmlFileMro in xmlFileListMro: # result = toCSV(xmlFile,csvPath) # 解析xml,并保存为csv文件 # 多进程解析xml,并保存为csv文件 po.apply_async(toCSV, args=(xmlFileMro, csvPathMro), callback=callback) print("----start----") po.close() # 关闭进程池,关闭后po不再接受新的请求 po.join() # 等待po中的所有子进程执行完成,必须放在close语句之后 '''如果没有添加join(),会导致有的代码没有运行就已经结束了''' print("-----end-----")
def testMuP(arg1): print(arg1) if __name__ == '__main__': # 最大的进程数为 为 CPU的核心数. po = Pool(cpu_count()) # 创建文件夹 unzipDirPath = os.path.abspath(unzipConf.xmlPath) if not os.path.exists(unzipDirPath): os.makedirs(unzipDirPath) # 获取压缩文件列表 zipFileList = getFileList(unzipConf.zipPath, r'.+\.') def callback(x): print(' {}'.format(current_process().name, x)) for zipFile in zipFileList: # 解压缩文件 # unzipFile(zipFile, unzipDirPath) po.apply_async(unzipFile, args=(zipFile, unzipDirPath), callback=callback) print("----start----") po.close() # 关闭进程池,关闭后po不再接受新的请求 po.join() # 等待po中的所有子进程执行完成,必须放在close语句之后
result = not insert_date(conn, curs,tableName,dbType,StringIO(output1)) except Exception as e: print(str(e)) if __name__ == '__main__': # try: # 初始化数据库连接 conn, curs = dbConnect.connDb(dbConfig.usedDbType) # 获取csv文件列表 csvFileList = getFileList(dbConfig.csvPath, r'.+\.csv') for csvFile in csvFileList: tableName,fileExtName = os.path.splitext(os.path.split(csvFile)[-1]) tableName = tableName.lower() # 检测表是否存在. isExistTable = dbConnect.isTableExist(conn, curs,tableName,dbConfig.usedDbType) # if not isExistTable: createTable.main() # 不存在就执行创建表的脚本 inDb(conn, curs, csvFile, tableName,dbConfig.usedDbType) # except Exception as e: # print(str(e)) # # finally: # if conn: dbConnect.close(conn,curs)