PopenPythonScript¶
- class lightning_app.components.python.popen.PopenPythonScript(script_path, script_args=None, env=None, **kwargs)[source]¶
Bases:
lightning_app.core.work.LightningWork
The PopenPythonScript component enables to easily run a python script within a subprocess.
- Parameters
- 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
Popen
.from pathlib import Path from lightning.app.components import PopenPythonScript if __name__ == "__main__": comp = PopenPythonScript(Path(__file__).parent / "pl_script.py") comp.run()