First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
The following should get you close:
import sys
import os
import multiprocessing
from multiprocessing import Pool as ThreadPool
import math
PSSE33BINPATH = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN;C:\Program Files (x86)\PTI\PSSE33\PSSLIB;"
def main():
processes = [] # setup blank list for processes
out_files = ['out1.out', 'out2.out', 'out3.out'] # set this to however you are grabbing your out files
file_number = 0 # not sure how you are giving file_number, so this is arbitrary
signals = ['Time'] # not sure what signals you are grabbing, so this is just an example
path_dir = r"C:\temp" # example
file_name = "channels" # example
# Change number_of_threads to how ever many threads you want to use, this is just an example of using all threads in CPU
number_of_threads = int(math.ceil(multiprocessing.cpu_count()))
# Loop through out files to setup an argument list
for out_file in out_files:
file_number += 1 # arbitrary
arguments = (out_file, signals, path_dir, file_name, file_number)
processes.append(arguments)
# Here I set number_of_threads to equal processes if I don't need to use all available threads
if len(processes) < number_of_threads:
number_of_threads = len(processes)
# Build pool and map your processes to it
out_pool = ThreadPool(number_of_threads)
results = out_pool.map(build_xls, processes)
out_pool.close()
out_pool.join() # Wait until all threads are finished
def build_xls((outfile, signals, path_dir, file_name, file_number)):
# The following may be different depending on PSSE version
os.environ['PATH'] = PSSE33BINPATH + ';' + os.environ['PATH']
sys.path.insert(0, PSSE33BINPATH)
import dyntools
excel_file = path_dir + "\\sheets\\" + file_name + str(file_number) + '.xlsx'
dyntools.CHNF(outfile).xlsout(channels=signals, show=False, xlsfile=excel_file, outfile='', sheet='', overwritesheet=True)
if __name__=='__main__':
main()