最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

linux - Is the singularity environment preserved for Python's subprocess? - Stack Overflow

programmeradmin1浏览0评论

I am working on a Python program and I wish to use Python's subprocess's run/Popen functions. I am working on a singularity environment and I found the following post which asks somewhat of a similar question but was left unanswered. I am running the Python from a singularity environment, is it preserved for the subprocesses?

I am working on a Python program and I wish to use Python's subprocess's run/Popen functions. I am working on a singularity environment and I found the following post which asks somewhat of a similar question but was left unanswered. I am running the Python from a singularity environment, is it preserved for the subprocesses?

Share Improve this question edited Feb 26 at 22:19 Sep Roland 39.7k9 gold badges48 silver badges88 bronze badges asked Dec 14, 2024 at 10:41 Niandra LadesNiandra Lades 678 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, when you run Python's subprocess functions from within a Singularity container, the subprocesses inherit the same container environment by default.

Here's an example to demonstrate this:

import subprocess
import os

# Print the current Python interpreter path (should be inside Singularity)
print("Parent process Python: ", sys.executable)

# Print some environment variable to confirm we're in Singularity
print("SINGULARITY_CONTAINER:", os.environ.get("SINGULARITY_CONTAINER", "Not in Singularity"))

# Run a subprocess and check its environment
result = subprocess.run(["which", "python"], capture_output=True, text=True)
print("Subprocess found Python at:", result.stdout.strip())

# Run another subprocess to confirm we're still in the same environment
env_result = subprocess.run(["printenv", "SINGULARITY_CONTAINER"], 
                           capture_output=True, text=True)
print("Subprocess Singularity env:", env_result.stdout.strip())
发布评论

评论列表(0)

  1. 暂无评论