docstr: The PopenPythonScript component enables to easily run a python script within a subprocess.
  
  Arguments:
      script_path: Path of the python script to run.
      script_path: The arguments to be passed to the script.
      env: Environment variables to be passed to the script.
      kwargs: LightningWork keyword arguments.
  
  Raises:
      FileNotFoundError: If the provided `script_path` doesn't exists.
  
  Example:
  
      >>> from lightning.app.components.python import PopenPythonScript
      >>> f = open("a.py", "w")
      >>> f.write("print('Hello World !')")
      22
      >>> f.close()
      >>> python_script = PopenPythonScript("a.py")
      >>> python_script.run()
      >>> os.remove("a.py")
  
  In this example, the script will be launch with the :class:`~subprocess.Popen`.
  
  .. literalinclude:: ../../../../examples/app/components/python/component_popen.py
      :language: python
docstr_tok: ["The","PopenPythonScript","component","enables","to","easily","run","a","python","script","within","a","subprocess",".","Arguments",":","script_path",":","Path","of","the","python","script","to","run",".","script_path",":","The","arguments","to","be","passed","to","the","script",".","env",":","Environment","variables","to","be","passed","to","the","script",".","kwargs",":","LightningWork","keyword","arguments",".","Raises",":","FileNotFoundError",":","If","the","provided","`","script_path","`","does","n't","exists",".","Example",":",">",">",">","from","lightning.app.components.python","import","PopenPythonScript",">",">",">","f","=","open","(","``","a.py","''",",","``","w","''",")",">",">",">","f.write","(","``","print","(","'Hello","World","!","'",")","''",")","22",">",">",">","f.close","(",")",">",">",">","python_script","=","PopenPythonScript","(","``","a.py","''",")",">",">",">","python_script.run","(",")",">",">",">","os.remove","(","``","a.py","''",")","In","this","example",",","the","script","will","be","launch","with","the",":","class",":","`","~subprocess.Popen","`",".","..","literalinclude",":",":","..","\/","..","\/","..","\/","..","\/examples\/app\/components\/python\/component_popen.py",":","language",":","python"]
code: def __init__(
      self,
      script_path: Union[str, Path],
      script_args: Optional[Union[str, List[str]]] = None,
      env: Optional[Dict] = None,
      **kwargs: Any,
  ):
      """The PopenPythonScript component enables to easily run a python script within a subprocess.
  
      Arguments:
          script_path: Path of the python script to run.
          script_path: The arguments to be passed to the script.
          env: Environment variables to be passed to the script.
          kwargs: LightningWork keyword arguments.
  
      Raises:
          FileNotFoundError: If the provided `script_path` doesn't exists.
  
      Example:
  
          >>> from lightning.app.components.python import PopenPythonScript
          >>> f = open("a.py", "w")
          >>> f.write("print('Hello World !')")
          22
          >>> f.close()
          >>> python_script = PopenPythonScript("a.py")
          >>> python_script.run()
          >>> os.remove("a.py")
  
      In this example, the script will be launch with the :class:`~subprocess.Popen`.
  
      .. literalinclude:: ../../../../examples/app/components/python/component_popen.py
          :language: python
  
      """
      super().__init__(**kwargs)
      if not os.path.exists(script_path):
          raise FileNotFoundError(
              f"The provided `script_path` {script_path}` wasn't found."
          )
      self.script_path = str(script_path)
      if isinstance(script_args, str):
          script_args = script_args.split(" ")
      self.script_args = script_args if script_args else []
      self.env = env
      self.pid = None
      self.exit_code = None
  
file_path: pytorch-lightning/src/lightning/app/components/python/popen.py
imports: import os
  import signal
  import subprocess
  import sys
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Union
  from lightning.app.core.work import LightningWork
  from lightning.app.utilities.app_helpers import Logger, _collect_child_process_pids
  from lightning.app.utilities.tracer import Tracer
label_desc: Use image node_id 4 to create a new PopenPythonScript object from inherited base classes: LightningWork with example: obj = PopenPythonScript(script_path, script_args, env)