Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had a go to implement a check when a sequential read of an iterator is interrupted. (See #891) I'm not really satisfied with the result, but I think it could be used as a basis for discussion.
First some background from gdals documentation:
OGR_L_GetFeature:
OGR_L_GetFeatureCount:
OGR_L_GetNextFeature is used in ogrext/Iterator. Iterator knows about the collection it was created from. Thus, the idea is to add a lock/flag to collection that is set if an iterator is started and released when he is finished. This flag is checked before OGR_L_GetFeature or OGR_L_GetFeatureCount is called. If a lock is set, a SequentialReadInterrupted exception is raised.
So far so good. But there are some issues with this approach. The first one is that an Iterator does not know when he is not used anymore. This is a problem for a membership test:
Here 0 in c would not release the lock, as never a StopIteration condition is reached. This can be fixed by implementing contains in Iterator to ensure that the lock is released. But there might be a better way to do this.
I found another issue with OGR_L_GetFeatureCount:
Debug Output:
Debug Output:
I'm not familiar with the implementation of list() in Python. I assume in the first case collection has a len method and list() tries to use it to create a list more efficiently, while Iterator has no len. I'm not sure why list calls len the second time, though. The second len is a problem as the sequential read lock is already set. This can be circumvented by checking for the lock in len.