Open multiple databases at once

Post Reply
ragopesa
Posts: 30
Joined: Thu Jun 08, 2023 12:08 am

Open multiple databases at once

Post by ragopesa » Sat Mar 15, 2025 8:02 pm

Hi STKO team,

I hope verything is going well.

I was hoping you can guide me. I would like to open multiple databases at once. Since I run many analysis, I'm experience several time to extract the result. I tried this:

Code: Select all

import os
import itertools
from concurrent.futures import ProcessPoolExecutor
from time import sleep
import importlib
import ThreadUtils
importlib.reload(ThreadUtils)
import ThreadUtils as tu
from PySide2.QtCore import Qt, QObject, Signal, Slot, QThread,QEventLoop
from PySide2.QtWidgets import QMessageBox, QApplication
from PyMpc import *
from PyMpc import MpcOdbVirtualResult as vr
import shutil
import glob
import multiprocessing
import numpy
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (
	QApplication,
	QDialog,
	QVBoxLayout,
	QProgressBar,
	QLabel,
	QListWidget,
	QListWidgetItem,
	QDialogButtonBox,
	QMessageBox,
	QInputDialog,
	QFileDialog,
	)

def files_(inifile):
	out = []
	for i in inifile:
		values = [os.path.join(i,j) for j in os.listdir(i)]
		out.append(values)
	output = sum(out, [])
	return output

#Limpiar terminal
App.clearTerminal()
doc = App.postDocument()

#### Datos de entrada
name_1 = 'rotation_outputs'
name_2 = 'rotation_sp_stko.txt'

ini_path       = r'D:\rocking_\1._0.05\3._12levels\Active_Shallow'
folders_ni     = [os.path.join(ini_path,i) for i in os.listdir(ini_path) if os.path.isdir(os.path.join(ini_path, i))]
fullpaths      = files_(folders_ni)
files          = []
db_id_to_close = []

for jindex,jitem in enumerate(fullpaths):
	os.chdir(jitem)
	for fileitem in glob.glob("*.mpco"):
		location = jitem + '\\' + fileitem
		files.append(location)

def open_database(filename):
    """Función que abre la base de datos"""
    App.runCommand('OpenDatabase', filename)
    
def Parallel_Analysis():
	with ProcessPoolExecutor() as executor:
		### submit all tasks
		for parameter in files:
			p = executor.submit(open_database,parameter)

if __name__ == '__main__':
    Parallel_Analysis()
This is just part of the code. The issue is that, when I run it, it actually opens multiple STKO windows, instead of openning only the databases. My idea is to open all the databases and the postprocessing. Could you please help me?

All the best,
Salvador
Salvador Ramos

ragopesa
Posts: 30
Joined: Thu Jun 08, 2023 12:08 am

Re: Open multiple databases at once

Post by ragopesa » Tue Mar 18, 2025 1:14 pm

Hi STKO team!!!

Could you please help me

Best
Salvador
Salvador Ramos

ragopesa
Posts: 30
Joined: Thu Jun 08, 2023 12:08 am

Re: Open multiple databases at once

Post by ragopesa » Fri Mar 21, 2025 7:11 am

Hi STKO team!!

Could you please help me ?

All the best
Salvador
Salvador Ramos

STKO Team
Posts: 2920
Joined: Tue Oct 29, 2019 8:45 am

Re: Open multiple databases at once

Post by STKO Team » Wed Apr 02, 2025 7:54 am

You cannot use a ProcessPoolExecutor like that. It does some tricks behind the scene that causes multiple instances of the python interpreter to be open (and in our case the interpreter is embedded inside STKO).

Post Reply