-
Notifications
You must be signed in to change notification settings - Fork 260
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
chore: Try to download Z3 5 times instead of just once #1835
Conversation
Scripts/package.py
Outdated
with request.urlopen(self.url) as reader: | ||
with open(self.z3_zip, mode="wb") as writer: | ||
writer.write(reader.read()) | ||
maxTries = 5 |
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.
At this point it might make sense to put this into a global constant. (With L132)
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.
But I do see the argument that we are dealing with events of a different nature here.
Scripts/package.py
Outdated
with open(self.z3_zip, mode="wb") as writer: | ||
writer.write(reader.read()) | ||
maxTries = 5 | ||
while maxTries > 0: |
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 might be cleaner in a for loop.
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.
It still have to check for the last bound to reraise the exception, but I converted it to a for loop with a global constant
Scripts/package.py
Outdated
maxTries -= 1 | ||
if maxTries == 0: | ||
raise | ||
continue |
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.
continue
is not needed here
try: | ||
with request.urlopen(self.url) as reader: | ||
with open(self.z3_zip, mode="wb") as writer: | ||
writer.write(reader.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.
urllib.request.urlretrieve
instead of write(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.
The documentation says your particular method has been deprecated.
Moreover, I don't feel comfortable editing what already worked before - for example, it might work today, but if the cache is outdated tomorrow and it does not work, we might not see the error
If you feel comfortable, feel free to contribute to this PR.
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.
The documentation says your particular method has been deprecated.
Not quite :) But I agree with you that it's fine to keep the current code if it's working (I wrote it, but I'm not sure why I didn't use shutil.copyfileobj
or urlretrieve
^^)
I wonder whether it might make sense to maintain a mapping from OS name to release files directly in this script, rather than asking the GitHub API for it. Something like |
Let's try that in a separate PR if the issue persists. |
Sanity check: we can't use the versions of Z3 in nuget can we? What if we eventually move to newer versions? |
We're building the release for multiple platforms. I don't think that's a service nuget provides. |
Scripts/package.py
Outdated
with open(self.z3_zip, mode="wb") as writer: | ||
writer.write(reader.read()) | ||
flush("done!") | ||
except (http.client.IncompleteRead) as e: |
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.
No need for parentheses here
except (http.client.IncompleteRead) as e: | ||
if currentAttempt == Z3_MAX_DOWNLOAD_ATTEMPTS - 1: | ||
raise | ||
|
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.
FWIW, an alternative way to write this kind of loop in Python is something like this (for-else
)
err = None
for _ in range(NRETRIES):
try:
do_something()
break
except SomeException as e:
err = e
else:
raise err
Co-authored-by: Fabio Madge <[email protected]>
I believe the Z3 NuGet package contains binaries for different platforms, but to use it you have to use a C# API instead of the textual SMTLib2 API that Boogie is using now, so that'd be significant updates to Boogie to support using that new API. |
Yes, looks like all you get is |
Problem
In one fo my last PR, the CI was not able to download Z3 in only 1 of the 15 instances.
This happens regularly (like, 1 time over 5) over an entire CI. Assuming that there are 10 runs every day, I don't want this problem to happen more than once a year.
Solution
With 5 tries, this problem will happen only 1 time every 3125, so that should get us covered.
Original exception