-
Notifications
You must be signed in to change notification settings - Fork 41
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
Robust client close #680
Robust client close #680
Conversation
Otherwise the queue could be joined before all polls are done, and client.close() would fail to terminate worker threads.
After client is closed, and its threadpools shutdown, we now reject requests to submit a problem, poll for status, cancel or download answer. We fail with a new exception, `UseAfterCloseError`.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #680 +/- ##
==========================================
+ Coverage 89.01% 89.10% +0.08%
==========================================
Files 44 44
Lines 4817 4846 +29
==========================================
+ Hits 4288 4318 +30
+ Misses 529 528 -1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me. I suppose something like
def require_initialized(method):
def _method(obj, *args, **kwargs):
if not obj._initialized:
raise UseAfterCloseError(f"{method.__name__} cannot be called after client has been closed")
return method(obj, *args, **kwargs)
return _method
might be a bit more uniform. But probably also overkill for what you're going for?
@@ -439,6 +440,8 @@ def from_config(cls, config_file=None, profile=None, client=None, **kwargs): | |||
def __init__(self, **kwargs): | |||
logger.debug("Client init called with: %r", kwargs) | |||
|
|||
self._initialized = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so that if there is an error in the next block we're still left in a valid state? Is it possible to detect whether the client is currently initialized via other attribute(s) saved on the object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make sure this flag is available in worker threads that are started before object finishes initializing. Ended up not needing the flag in workers, but still it's probably safer this way.
This seems obvious now that I'm seeing it repeated so many times in the diff.. 😄 Will change, thanks! |
Co-authored-by: Alexander Condello <arcondello@gmail.com>
7a9934f
to
26a74f3
Compare
Close #217.