Skip to content

Commit

Permalink
Be precise about repr() in exceptions
Browse files Browse the repository at this point in the history
Be precise about intention to use `repr()` in the message/exception formats.
These are NFC statement changes because `__str__` is not currently defined.
(Should it ever become so, "now we're prepared.")

While here, more fully match the Executor specification to raise a
`RuntimeError` for `.map()` as well, if called after shutdown.
  • Loading branch information
khk-globus committed Dec 12, 2023
1 parent 1ebceb2 commit 6938d1d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions compute_sdk/globus_compute_sdk/sdk/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ def register_function(
registration upstream
"""
if self._stopped:
err_fmt = "%s is shutdown; refusing to register function"
raise RuntimeError(err_fmt % repr(self))
raise RuntimeError(f"{self!r} is shutdown; refusing to register function")

fn_cache_key = self._fn_cache_key(fn)
if fn_cache_key in self._function_registry:
Expand Down Expand Up @@ -427,8 +426,8 @@ def submit(self, fn, *args, **kwargs):
a ``.result()`` when the Globus Compute web services receive and stream it.
"""
if self._stopped:
err_fmt = "%s is shutdown; no new functions may be executed"
raise RuntimeError(err_fmt % repr(self))
err = f"{self!r} is shutdown; no new functions may be executed"
raise RuntimeError(err)

fn_cache_key = self._fn_cache_key(fn)
if fn_cache_key not in self._function_registry:
Expand Down Expand Up @@ -494,8 +493,8 @@ def some_processor(*args, **kwargs):
when the Globus Compute web services receive and stream it.
"""
if self._stopped:
err_fmt = "%s is shutdown; no new functions may be executed"
raise RuntimeError(err_fmt % repr(self))
err = f"{self!r} is shutdown; no new functions may be executed"
raise RuntimeError(err)

if not self.endpoint_id:
msg = (
Expand Down Expand Up @@ -545,9 +544,16 @@ def map(fxexec, fn, *fn_args_kwargs):
Raises
------
RuntimeError
if called after shutdown, otherwise, ...
NotImplementedError
always raised
... always raised
""" # noqa
if self._stopped:
err = f"{self!r} is shutdown; no new functions may be executed"
raise RuntimeError(err)

raise NotImplementedError()

def reload_tasks(
Expand Down

0 comments on commit 6938d1d

Please sign in to comment.