-
Notifications
You must be signed in to change notification settings - Fork 108
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
wrap tasks in a while loop to avoid exceptions outside the Try/Except block #281
Conversation
@@ -301,7 +301,7 @@ def tile( | |||
tile = mercantile.Tile(x=tile_x, y=tile_y, z=tile_z) | |||
if not tile_exists(self.bounds, tile_z, tile_x, tile_y): | |||
raise TileOutsideBounds( | |||
"Tile {}/{}/{} is outside image bounds".format(tile_z, tile_x, tile_y) | |||
f"Tile {tile_z}/{tile_x}/{tile_y} is outside {self.filepath} bounds" |
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.
add a bit more info on this exception
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.
You know I love my f-strings 😉
try: | ||
future, asset = next(tasks) # type: ignore |
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.
Not sure why mypy wasn't happy here
if isinstance(future, futures.Future): | ||
yield future.result(), asset | ||
else: | ||
yield future, asset | ||
except StopIteration: |
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.
we put StopIteration first, so someone doesn't try to put StopIteration as allowed_exceptions
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.
They might wonder why their endless loop is slow...
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.
well if they do that (putting StopIteration in allowed_exception) the while loop while never exit ...
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.
haha yes, hence the loop will never end and will be slow 😄
(executor.submit(reader, asset, *args, **kwargs), asset) | ||
for asset in assets | ||
] | ||
return iter( |
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.
wrapping the futures inside an iterator to be able to use next
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.
You might just be able to use a generator comprehension instead? Replace the [ ]
with parentheses?
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.
tried and it didn't work 🤷♂️
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 think because the future needs to be executed with the excetutor. if you use a generator, the code will be run outide (in the filer function)
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.
That makes sense 👍
No description provided.