diff --git a/examples/input_data_callback.py b/examples/input_data_callback.py index 92fe7d56..ccce25ee 100644 --- a/examples/input_data_callback.py +++ b/examples/input_data_callback.py @@ -56,5 +56,6 @@ class MyPipeline(Pipen): data = [prepare_input_data()] forks = 3 + if __name__ == "__main__": MyPipeline().run() diff --git a/examples/mako-templating.py b/examples/mako-templating.py index 0068bc82..e21cf25b 100644 --- a/examples/mako-templating.py +++ b/examples/mako-templating.py @@ -4,6 +4,7 @@ from pipen.template import Template from pipen import Proc, Pipen + class TemplateMako(Template): name = "mako" diff --git a/examples/multijobs.py b/examples/multijobs.py index 062f0045..a44d86a6 100644 --- a/examples/multijobs.py +++ b/examples/multijobs.py @@ -1,6 +1,7 @@ """An example for a process to have multiple jobs and run jobs in parallel""" from pipen import Proc, Pipen + class MultiJobProc(Proc): """A process with multiple jobs""" input = "i" @@ -12,5 +13,6 @@ class MultiJobProc(Proc): # Let the job takes long the see the parallelization from the progressbar script = "sleep 1; echo {{in.i}} > {{out.outfile}}" + if __name__ == "__main__": Pipen().set_starts(MultiJobProc).run() diff --git a/examples/plugin-example.py b/examples/plugin-example.py index a3cd764a..5d27318e 100644 --- a/examples/plugin-example.py +++ b/examples/plugin-example.py @@ -5,6 +5,7 @@ logger = get_logger("notify", "info") + class NotifyPlugin: version = "0.0.0" @@ -28,8 +29,10 @@ async def on_proc_start(proc): async def on_proc_done(proc, succeeded): logger.info("Calling on_proc_done, succeeded = %s", succeeded) + class AProcess(Proc): input = "a" + if __name__ == "__main__": Pipen(plugins=[NotifyPlugin]).set_starts(AProcess).run() diff --git a/examples/python-script.py b/examples/python-script.py index 09ba98e1..0b5f2963 100644 --- a/examples/python-script.py +++ b/examples/python-script.py @@ -2,6 +2,7 @@ from pipen import Pipen, Proc + class PythonScriptProc(Proc): """A process using python interpreter for script""" input = "a" @@ -13,5 +14,6 @@ class PythonScriptProc(Proc): Path("{{out.outfile}}").write_text("{{in.a}}") """ + if __name__ == "__main__": Pipen().set_starts(PythonScriptProc).run() diff --git a/examples/retry.py b/examples/retry.py index ebbb378b..e4064a07 100644 --- a/examples/retry.py +++ b/examples/retry.py @@ -2,6 +2,7 @@ import time from pipen import Pipen, Proc + class RetryProc(Proc): """Retry the jobs when fail""" input = "starttime" @@ -10,13 +11,19 @@ class RetryProc(Proc): # Make sure the job succeeds finally num_retries = 10 script = """ - if [[ $(date +"%s") -gt {{in.starttime + 3}} ]]; then + timefile="{{job.outdir}}/time.txt" + now=$(date +"%s") + expect={{in.starttime + 10}} + if [[ $now -gt $expect ]]; then + echo $now $expect 0 >> "$timefile" exit 0 else + echo $now $expect 1 >> "$timefile" exit 1 fi """ + if __name__ == "__main__": # Show debug information so we see the retrying message Pipen(loglevel="debug").set_starts(RetryProc).run()