-
Notifications
You must be signed in to change notification settings - Fork 2
Condition wait #5
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
Conversation
time.sleep(n) is a kernel call that pauses the entire Python interpreter, Python threads a virtual. Using condition.wait(n) lets the other threads execute while waiting, this bypasses the GIL (global interpreter lock).
Added workflow to enable tests after commit.
…ime.sleep to avoid Global Interpreter Lock (GIL).
…ead of time.sleep to avoid Global Interpreter Lock (GIL).
|
Thanks! Any chance that you may rebase it on the latest commit in the |
retry/api.py
Outdated
| fail_callback(e) | ||
|
|
||
| with ConditionRelease(condition) as _condition: | ||
| print('_condtion:', _condition) |
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.
Does it really need to print to stdout or did you want to add some logging?
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.
removing.
retry/api.py
Outdated
| class ConditionRelease(object): | ||
| def __init__(self, c): | ||
| self.c = c | ||
| def __enter__(self): | ||
| self.c.acquire() | ||
| return self | ||
| def wait(self, n): | ||
| self.c.wait(n) | ||
| def __exit__(self, exc_type, exc_value, exc_tb): | ||
| self.c.release() |
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.
Can a contextlib.contextmanager be used instead? Would it make it simpler?
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.
Will change the context manager class, but contextmanager decorator alone is not something that seems fullproof enough. This context manager class will make code easier to read.
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.
Another question -- you propose that all the old tests should now have threads in them. Shouldn't you create a new set of tests for your new feature?
removed some stdout prints, changed the context class.
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.
Sorry, it still hasn't been rebased on the latest commit in reretry:mater. It contains merge conflicts which I am afraid I am unable to resolve.
| @@ -0,0 +1,37 @@ | |||
| # This workflow will install Python dependencies, run tests and lint with a single version of Python | |||
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.
.github/workflows/pythonapp.yml - it seem like this file should not be here
README.rst
Outdated
| :param condition: threading.Condition or multiprocessing.Condition or any construct that | ||
| has acquire(), release() and wait(n) |
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.
README.rst was superceded by README.md
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 2.58%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
|
I'd like to withdraw the request, this link explain why it is not needed: Thanks. |
Pulled the code from leshchenko1979/reretry, modified api.py and test_retry.py so that only the condition_wait changes are added.
Done to comply with request on this link: invl#48 (comment)
Thanks.