WorkingWithProcesses

This wiki is in the process of being archived due to lack of usage and the resources necessary to serve it — predominately to bots, crawlers, and LLM companies. Edits are discouraged.
Pages are preserved as they were at the time of archival. For current information, please visit python.org.
If a change to this archive is absolutely needed, requests can be made via the infrastructure@python.org mailing list.

These are just some notes about working with processes in Python.

The module of interest is os. (os module documentation)

Environment variables are accessed through a dictionary, os.environ.

Processes are created with os.popen, described in os 6.1.2.

 1 import os
 2 
 3 # Export an environment variable
 4 os.environ["FOO"] = "BAR"
 5 
 6 # Make sure environment variable set for child processes
 7 for line in os.popen("bash -c 'env'").read().splitlines():
 8  if line.startswith("FOO="):
 9  print line
 10 
 11 # Since environment variable "FOO" is exported, and since child
 12 # processes inherit environment variables from their parents, this
 13 # works.

2026年02月14日 16:15

AltStyle によって変換されたページ (->オリジナル) /