PopenPythonScript¶
- class lightning.app.components.python.popen.PopenPythonScript(script_path, script_args=None, env=None, **kwargs)¶
Bases:
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()
- configure_tracer()¶
Override this hook to customize your tracer when running PythonScript with
mode=tracer
.- Return type
Tracer
- on_after_run()¶
Called after the python script is executed.
- on_before_run()¶
Called before the python script is executed.
- on_exit()¶
Override this hook to add your logic when the work is exiting.
Note: This hook is not guaranteed to be called when running in the cloud.