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

379 round robin pipe iterator #421

Merged
merged 6 commits into from
Jun 16, 2023
Merged

Conversation

sh-rp
Copy link
Collaborator

@sh-rp sh-rp commented Jun 15, 2023

implements #379

@netlify
Copy link

netlify bot commented Jun 15, 2023

Deploy Preview for dlt-hub-docs ready!

Name Link
🔨 Latest commit d1fefc6
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/648c626b9e7c5a0008c950c3
😎 Deploy Preview https://deploy-preview-421--dlt-hub-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Collaborator

@rudolfix rudolfix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's one important things in the ticket #379

that the newly added sources (gens) must be ALWAYS evaluated before those added by intialization.

execution of the step may create a generator. to preserve any deadlocks we evaluate the newly added generators without the round robin. see the ticket.

def _get_source_item_round_robin(self) -> ResolvablePipeItem:
try:
# get items from last added iterator, this makes the overall Pipe as close to FIFO as possible
self._round_robin_index = self._round_robin_index % len(self._sources)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd start the index at -1 and increase it by 1 here then takin modulo in the next line. so we save on assignment. I know I'm pedantic but this is the most frequently called piece of code

self._round_robin_index -= 1
# remove empty iterator and try another source
self._sources.pop(self._round_robin_index)
return self._get_source_item()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the round robin again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the code a bit, and it has to stay like this for round robin and current to work in conjunction

@@ -670,13 +676,18 @@ def _get_source_item(self) -> ResolvablePipeItem:
# no more sources to iterate
if len(self._sources) == 0:
return None
if self._next_item_mode == "current":
return self._get_source_item_current()
if self._next_item_mode == "round_robin":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do elif because it is faster

@@ -15,6 +15,35 @@
# from tests.utils import preserve_environ


def test_next_item_mode() -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good test!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's even better now :D

@sh-rp sh-rp force-pushed the d#/379-round-robin-pipe-iterator branch from e038023 to 577c244 Compare June 16, 2023 10:10
yield from [1, 2, nested_gen(), 3,4]

def source_gen2():
yield from range(11,16)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just intuition: could you add nested gen at the end of the range?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to work without a problem


# test mode "round robin"
reversed_pipes = get_pipes()
reversed_pipes.reverse() # reverse order of pipes for easier testing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! this actually must be reversed in the code, not in the test. the first pipe in the list must be evaluated first! I think I reverse the them inside so skip the reverse for round robin

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@rudolfix rudolfix marked this pull request as ready for review June 16, 2023 15:33
@sh-rp sh-rp merged commit 9010fe8 into devel Jun 16, 2023
31 checks passed
@rudolfix rudolfix deleted the d#/379-round-robin-pipe-iterator branch June 18, 2023 19:48
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

Successfully merging this pull request may close these issues.

None yet

2 participants