#9307 Python: avoid assigning same port number to multiple grpc sessions

* Python: avoid assigning same port number to multiple grpc sessions
* Add retry count when checking for port number file
* Use grpc to find and use port number
* Add test used to start several instances of resinsight at the same time
Testing up to 50 instances works well

* Python: allow launch_port == 0 to assign port by GRPC in Instance.launch().
Also allow longer wait before failing the port number file reading:
it can take some time to launch when launching lots of instances at
the same time.
This commit is contained in:
Kristian Bendiksen
2022-09-26 14:19:21 +02:00
committed by GitHub
parent 587f700ae4
commit c2b5ab8d2c
7 changed files with 165 additions and 36 deletions

View File

@@ -33,6 +33,8 @@
#include "cvfProgramOptions.h"
#include "cvfqtUtils.h"
#include <QFile>
#ifndef WIN32
#include <sys/types.h>
#include <unistd.h>
@@ -145,6 +147,28 @@ int main( int argc, char* argv[] )
if ( grpcInterface && grpcInterface->initializeGrpcServer( progOpt ) )
{
grpcInterface->launchGrpcServer();
if ( cvf::Option o = progOpt.option( "portnumberfile" ) )
{
if ( o.valueCount() == 1 )
{
int portNumber = grpcInterface->portNumber();
QString fileName = QString::fromStdString( o.value( 0 ).toStdString() );
// Write port number to the file given file.
// Temp file is used to avoid incomplete reads.
QString tempFilePath = fileName + ".tmp";
QFile file( tempFilePath );
if ( file.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
QTextStream out( &file );
out << portNumber << endl;
}
file.close();
QFile::rename( tempFilePath, fileName );
}
}
}
#endif
exitCode = QCoreApplication::instance()->exec();