Skip to content
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

Merged

Conversation

randomir
Copy link
Member

Close #217.

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`.
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.10%. Comparing base (90de738) to head (26a74f3).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
dwave/cloud/client/base.py 91.30% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@randomir randomir requested a review from arcondello January 21, 2025 16:18
Copy link
Member

@arcondello arcondello left a 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
Copy link
Member

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?

Copy link
Member Author

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.

@randomir
Copy link
Member Author

Seems reasonable to me. I suppose something like
[...]
might be a bit more uniform. But probably also overkill for what you're going for?

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>
@randomir randomir force-pushed the feature/robust-client-close/issue-217 branch from 7a9934f to 26a74f3 Compare January 22, 2025 15:20
@randomir randomir merged commit 59f8baa into dwavesystems:master Jan 22, 2025
33 checks passed
@randomir randomir deleted the feature/robust-client-close/issue-217 branch January 22, 2025 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Robust Client.close(), no client/solver/future reuse after close
2 participants