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

Koza doesn't play nicely with generators #144

Open
DnlRKorn opened this issue Aug 16, 2024 · 2 comments
Open

Koza doesn't play nicely with generators #144

DnlRKorn opened this issue Aug 16, 2024 · 2 comments
Assignees

Comments

@DnlRKorn
Copy link
Contributor

I tried to replace the following line of code

while (row := koza_app.get_row()) is not None:
xyz

with

koza_app = get_koza_app("go_annotation")
def row_gen():   while True:
       try:
           row = koza_app.get_row()
           yield row
       except StopIteration:
           return

for row in row_gen():
   xyz

But this caused some form of infinite loop to begin firing within the koza module

2024-08-16_14:09:34 | INFO | koza.io.reader.csv_reader | Finished processing 19 rows for go_annotation from file data/go/9606.go_annotations.gaf.gz
2024-08-16_14:09:34 | INFO | koza.io.reader.csv_reader | Finished processing 19 rows for go_annotation from file data/go/9606.go_annotations.gaf.gz
2024-08-16_14:09:34 | INFO | koza.io.reader.csv_reader | Finished processing 19 rows for go_annotation from file data/go/9606.go_annotations.gaf.gz
2024-08-16_14:09:34 | INFO | koza.io.reader.csv_reader | Finished processing 19 rows for go_annotation from file data/go/9606.go_annotations.gaf.gz
2024-08-16_14:09:34 | INFO | koza.io.reader.csv_reader | Finished processing 19 rows for go_annotation from file data/go/9606.go_annotations.gaf.gz

@ptgolden ptgolden self-assigned this Oct 29, 2024
@ptgolden
Copy link
Member

I'm fairly sure the issue here is that koza expects StopIteration to be raised to know when to stop running the transform script. Since that exception is never raised, the script continues to be run

@ptgolden
Copy link
Member

i.e. it never breaks out of this loop:

koza/src/koza/app.py

Lines 102 to 119 in fceafe5

while True:
try:
if is_first:
transform_module = importlib.import_module(transform_code)
is_first = False
else:
importlib.reload(transform_module)
except MapItemException as mie:
if self.logger:
self.logger.debug(f"{str(mie)} not found in map")
except NextRowException:
continue
except ValidationError:
if self.logger:
self.logger.error(f"Validation error while processing: {self.source.last_row}")
raise ValidationError
except StopIteration:
break

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

No branches or pull requests

2 participants