.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_file_creation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_example_file_creation.py: Create a file ============= .. GENERATED FROM PYTHON SOURCE LINES 5-15 .. code-block:: Python from pathlib import Path from remote_run import ( Executor, GuixEnvironment, remote, SshMachine, ) import pickle .. GENERATED FROM PYTHON SOURCE LINES 16-17 Define an executor .. GENERATED FROM PYTHON SOURCE LINES 17-31 .. code-block:: Python executor = Executor( machine=SshMachine( host="shpc0003.ost.ch", working_directory=Path("/cluster/raid/home/reza.housseini"), ), environments=[ GuixEnvironment( channels=Path("channels.scm").read_text(), manifest=Path("manifest.scm").read_text(), ) ], ) .. GENERATED FROM PYTHON SOURCE LINES 32-34 decorate your function you want to run with an executor with the remote decorator .. GENERATED FROM PYTHON SOURCE LINES 34-41 .. code-block:: Python @remote def create_file(text): a_file = Path("a_file") a_file.write_text(text) return a_file .. GENERATED FROM PYTHON SOURCE LINES 42-46 this call will run on the machine specified in the executor. When returning argument of type Path, the file will be downloaded from the machine and the path will be patched to point to this new location. .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python job = create_file("hello", executor=executor) .. GENERATED FROM PYTHON SOURCE LINES 49-50 I can also pickle the job and retrieve for later use .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python job_file = Path("job_file") job_file.write_bytes(pickle.dumps(job)) .. GENERATED FROM PYTHON SOURCE LINES 54-55 after getting the result, the file will be available locally .. GENERATED FROM PYTHON SOURCE LINES 55-58 .. code-block:: Python job = pickle.loads(job_file.read_bytes()) result = job.result() assert result.read_text() == "hello" .. _sphx_glr_download_auto_examples_example_file_creation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_file_creation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_file_creation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_file_creation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_