-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LazyProxy and LazyProxyMultiton patterns #269
Conversation
@JSKenyon @bennahugo @o-smirnov The purpose of this PR is to demonstrate two useful patterns for managing resources in a dask context. I'll briefly describe the The instance is only created when attempts to access attributes on it via the f = LazyProxy(open, "test.txt", mode="w")
f.write("Hello World")
f.close() Additionally, it's possible to supply a def finalise(file_):
file_.close()
f = LazyProxy((open, finalise), "test.txt", mode="w")
f.write("Hello World")
assert LazyProxy(open, "test.txt", mode="w") is not LazyProxy(open, "test.txt", mode="w")
assert LazyProxyMultiton(open, "test.txt", mode="w") is LazyProxyMultiton(open, "test.txt", mode="w") I would like to discuss these patterns over the next couple of weeks in a meeting. |
It works for submitting parangle computation to to "spawn" Process Pools |
Thanks @sjperkins for taking the time to demonstrate this pattern. I can confirm that this works, with the caveat that in the distributed case it is still necessary to set |
Functions like dask.blockwise rely on duck typing to make decisions about the objects that they are inserting into the graph. This is undesirable in the case of LazyProxy's as they generally represent heavy resource objects like Files, Sockets or Database Connections. This commit ensures that LazyObject creation does not take place within a call context that would unnecessarily incur LazyObject creation, like dask.array.blockwise.
Tests added / passed
If the pep8 tests fail, the quickest way to correct
this is to run
autopep8
and thenflake8
andpycodestyle
to fix the remaining issues.Fully documented, including
HISTORY.rst
for all changesand one of the
docs/*-api.rst
files for new APITo build the docs locally: