Skip to content

Instantly share code, notes, and snippets.

@jsignell
Created February 25, 2021 14:32
Show Gist options
  • Save jsignell/5a97afbdaadb2a038692178b3c5dd4b9 to your computer and use it in GitHub Desktop.
Save jsignell/5a97afbdaadb2a038692178b3c5dd4b9 to your computer and use it in GitHub Desktop.
Simple file upload worker plugin for dask.
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