tvalentyn commented on code in PR #38853:
URL: https://github.com/apache/beam/pull/38853#discussion_r3384020971
##########
sdks/python/container/boot.go:
##########
@@ -333,12 +347,68 @@ func launchSDKProcess() error {
childPids.mu.Unlock()
return
}
- logger.Printf(ctx, "Executing Python (worker
%v): python %v", workerId, strings.Join(args, " "))
- cmd :=
StartCommandEnv(map[string]string{"WORKER_ID": workerId}, os.Stdin, bufLogger,
bufLogger, "python", args...)
+
+ currentProg := "python"
+ currentArgs := []string{"-m",
sdkHarnessEntrypoint}
+ currentEnv := map[string]string{"WORKER_ID":
workerId}
+
+ profilingActive := false
+ currentProg, currentArgs, currentEnv,
profilingActive = maybeWithProfiler(
+ ctx, logger, workerId, currentProg,
currentArgs, currentEnv,
+ )
+
+ var envStr string
+ if len(currentEnv) > 0 {
+ var envStrings []string
+ for k, v := range currentEnv {
+ envStrings = append(envStrings,
k+"="+v)
+ }
+ slices.Sort(envStrings)
+ envStr = strings.Join(envStrings, ", ")
+ }
+
+ logger.Printf(ctx, "Executing Python (%v): %v
%v", envStr, currentProg, strings.Join(currentArgs, " "))
+ cmd := StartCommandEnv(currentEnv, os.Stdin,
bufLogger, bufLogger, currentProg, currentArgs...)
childPids.v = append(childPids.v,
cmd.Process.Pid)
childPids.mu.Unlock()
- if err := cmd.Wait(); err != nil {
+ var timer *time.Timer
+ var profilingTimedOut atomic.Bool
+
+ pcfg := getProfilerConfig(ctx)
+ if profilingActive && pcfg != nil &&
pcfg.StopAfterSec > 0 {
+ duration :=
time.Duration(pcfg.StopAfterSec) * time.Second
+ timer = time.AfterFunc(duration, func()
{
+ childPids.mu.Lock()
+ defer childPids.mu.Unlock()
+ if cmd.Process != nil {
+ logger.Printf(ctx,
"Profiling timeout of %d seconds reached. Sending SIGINT to worker %s",
+
pcfg.StopAfterSec, workerId)
+
profilingTimedOut.Store(true)
+
syscall.Kill(-cmd.Process.Pid, syscall.SIGINT)
Review Comment:
we do use
// Create process group so we can clean up the whole subtree later
without creating zombies
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]