2828
2929#include < filesystem>
3030
31- #include " python_be.h"
3231#include " pb_utils.h"
32+ #include " python_be.h"
3333
3434#ifdef _WIN32
3535#include < process.h> // getpid()
3636#endif
3737
38- extern char ** environ;
38+ extern char ** environ;
3939
4040namespace triton { namespace backend { namespace python {
4141
@@ -345,13 +345,13 @@ StubLauncher::Launch()
345345 TRITONSERVER_ERROR_INVALID_ARG,
346346 " Invalid stub name: contains invalid characters" );
347347 }
348-
348+
349349 if (!IsValidPath (model_path_)) {
350350 return TRITONSERVER_ErrorNew (
351351 TRITONSERVER_ERROR_INVALID_ARG,
352352 " Invalid model path: contains invalid characters or not absolute" );
353353 }
354-
354+
355355 if (!IsValidIdentifier (shm_region_name_)) {
356356 return TRITONSERVER_ErrorNew (
357357 TRITONSERVER_ERROR_INVALID_ARG,
@@ -372,12 +372,12 @@ StubLauncher::Launch()
372372 // Validate the stub executable path
373373 if (!IsValidPath (python_backend_stub)) {
374374 return TRITONSERVER_ErrorNew (
375- TRITONSERVER_ERROR_INVALID_ARG,
376- " Invalid python backend stub path" );
375+ TRITONSERVER_ERROR_INVALID_ARG, " Invalid python backend stub path" );
377376 }
378377
379378 if (!IsExecutableFile (python_backend_stub)) {
380- // Give the execute permission for the triton_python_backend_stub to the owner.
379+ // Give the execute permission for the triton_python_backend_stub to the
380+ // owner.
381381 int error = chmod (python_backend_stub.c_str (), S_IXUSR);
382382 if (error != 0 ) {
383383 return TRITONSERVER_ErrorNew (
@@ -398,24 +398,24 @@ StubLauncher::Launch()
398398 // revert the LD_LIBRARY_PATH changes to avoid shared library issues in
399399 // executables and libraries.
400400 ipc_control_->uses_env = false ;
401-
401+
402402 if (python_execution_env_ != " " ) {
403-
404403 // Validate Python environment paths
405404 if (!IsValidPath (path_to_activate_) || !IsValidPath (path_to_libpython_)) {
406405 return TRITONSERVER_ErrorNew (
407- TRITONSERVER_ERROR_INVALID_ARG,
408- " Invalid Python environment paths" );
406+ TRITONSERVER_ERROR_INVALID_ARG, " Invalid Python environment paths" );
409407 }
410-
408+
411409 ipc_control_->uses_env = true ;
412-
410+
413411 // Parse environment variables from activation script
414- std::map<std::string, std::string> env_vars = ParseActivationScript (path_to_activate_);
415-
416- // Prepare environment with additional library path
417- auto [env_strings, custom_env] = PrepareEnvironment (env_vars, path_to_libpython_);
418-
412+ std::map<std::string, std::string> env_vars =
413+ ParseActivationScript (path_to_activate_);
414+
415+ // Prepare environment with additional library path
416+ auto [env_strings, custom_env] =
417+ PrepareEnvironment (env_vars, path_to_libpython_);
418+
419419 // Set up arguments for direct execution
420420 arg_strings.push_back (python_backend_stub);
421421 arg_strings.push_back (model_path_);
@@ -427,7 +427,7 @@ StubLauncher::Launch()
427427 arg_strings.push_back (std::to_string (ipc_control_handle_));
428428 arg_strings.push_back (stub_name);
429429 arg_strings.push_back (runtime_modeldir_);
430-
430+
431431 // Convert strings to char* array for exec
432432 for (const auto & arg : arg_strings) {
433433 exec_args.push_back (arg.c_str ());
@@ -437,12 +437,15 @@ StubLauncher::Launch()
437437 // Log the command being executed
438438 std::ostringstream log_cmd;
439439 for (size_t i = 0 ; i < arg_strings.size (); ++i) {
440- if (i > 0 ) log_cmd << " " ;
440+ if (i > 0 )
441+ log_cmd << " " ;
441442 log_cmd << " '" << arg_strings[i] << " '" ;
442443 }
443444 LOG_MESSAGE (
444445 TRITONSERVER_LOG_VERBOSE,
445- (std::string (" Starting Python backend stub with custom environment: " ) + log_cmd.str ()).c_str ());
446+ (std::string (" Starting Python backend stub with custom environment: " ) +
447+ log_cmd.str ())
448+ .c_str ());
446449
447450 pid_t pid = fork ();
448451 if (pid < 0 ) {
@@ -451,11 +454,16 @@ StubLauncher::Launch()
451454 " Failed to fork the stub process for auto-complete." );
452455 }
453456 if (pid == 0 ) {
454- // Replace this child process with the new stub process using custom environment
455- execve (python_backend_stub.c_str (), const_cast <char **>(exec_args.data ()), custom_env.data ());
457+ // Replace this child process with the new stub process using custom
458+ // environment
459+ execve (
460+ python_backend_stub.c_str (), const_cast <char **>(exec_args.data ()),
461+ custom_env.data ());
456462 // execve() never returns if succeeded. Otherwise, an error has occurred.
457463 std::stringstream ss;
458- ss << " Failed to run python backend stub with custom environment. Errno = " << errno << ' \n '
464+ ss << " Failed to run python backend stub with custom environment. Errno "
465+ " = "
466+ << errno << ' \n '
459467 << " Python backend stub path: " << python_backend_stub << ' \n '
460468 << " Activation script: " << path_to_activate_ << ' \n '
461469 << " Library path: " << path_to_libpython_ << ' \n ' ;
@@ -464,7 +472,7 @@ StubLauncher::Launch()
464472 } else {
465473 stub_pid_ = pid;
466474 }
467-
475+
468476 } else {
469477 arg_strings.push_back (python_backend_stub);
470478 arg_strings.push_back (model_path_);
@@ -476,7 +484,7 @@ StubLauncher::Launch()
476484 arg_strings.push_back (std::to_string (ipc_control_handle_));
477485 arg_strings.push_back (stub_name);
478486 arg_strings.push_back (runtime_modeldir_);
479-
487+
480488 // Convert strings to char* array for exec
481489 for (const auto & arg : arg_strings) {
482490 exec_args.push_back (arg.c_str ());
@@ -486,12 +494,14 @@ StubLauncher::Launch()
486494 // Log the command being executed
487495 std::ostringstream log_cmd;
488496 for (size_t i = 0 ; i < arg_strings.size (); ++i) {
489- if (i > 0 ) log_cmd << " " ;
497+ if (i > 0 )
498+ log_cmd << " " ;
490499 log_cmd << " '" << arg_strings[i] << " '" ;
491500 }
492501 LOG_MESSAGE (
493502 TRITONSERVER_LOG_VERBOSE,
494- (std::string (" Starting Python backend stub: " ) + log_cmd.str ()).c_str ());
503+ (std::string (" Starting Python backend stub: " ) + log_cmd.str ())
504+ .c_str ());
495505
496506 pid_t pid = fork ();
497507 if (pid < 0 ) {
@@ -974,6 +984,6 @@ StubLauncher::ShareCUDAMemoryPool(
974984 if (pb_exception.what () != std::string{" " }) {
975985 throw pb_exception;
976986 }
977- }
978- #endif // TRITON_ENABLE_GPU
987+ }
988+ #endif // TRITON_ENABLE_GPU
979989}}}; // namespace triton::backend::python
0 commit comments