Created
February 25, 2021 14:32
-
-
Save jsignell/5a97afbdaadb2a038692178b3c5dd4b9 to your computer and use it in GitHub Desktop.
Simple file upload worker plugin for dask.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from distributed import WorkerPlugin | |
class UploadFile(WorkerPlugin): | |
"""A WorkerPlugin to upload a local file to workers. | |
Parameters | |
---------- | |
filepath: str | |
A path to the file to upload | |
Examples | |
-------- | |
>>> client.register_worker_plugin(UploadFile(".env")) | |
""" | |
def __init__(self, filepath): | |
""" | |
Initialize the plugin by reading in the data from the given file. | |
""" | |
self.filename = os.path.basename(filepath) | |
with open(filepath, "rb") as f: | |
self.data = f.read() | |
async def setup(self, worker): | |
with open(self.filename, "wb+") as f: | |
f.write(self.data) | |
return os.listdir() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment