Generate the full, unsorted collection of PostSortRecs as well as dependency pairs for this UOWTransaction.
(self)
| 386 | yield state |
| 387 | |
| 388 | def _generate_actions(self): |
| 389 | """Generate the full, unsorted collection of PostSortRecs as |
| 390 | well as dependency pairs for this UOWTransaction. |
| 391 | |
| 392 | """ |
| 393 | # execute presort_actions, until all states |
| 394 | # have been processed. a presort_action might |
| 395 | # add new states to the uow. |
| 396 | while True: |
| 397 | ret = False |
| 398 | for action in list(self.presort_actions.values()): |
| 399 | if action.execute(self): |
| 400 | ret = True |
| 401 | if not ret: |
| 402 | break |
| 403 | |
| 404 | # see if the graph of mapper dependencies has cycles. |
| 405 | self.cycles = cycles = topological.find_cycles( |
| 406 | self.dependencies, list(self.postsort_actions.values()) |
| 407 | ) |
| 408 | |
| 409 | if cycles: |
| 410 | # if yes, break the per-mapper actions into |
| 411 | # per-state actions |
| 412 | convert = { |
| 413 | rec: set(rec.per_state_flush_actions(self)) for rec in cycles |
| 414 | } |
| 415 | |
| 416 | # rewrite the existing dependencies to point to |
| 417 | # the per-state actions for those per-mapper actions |
| 418 | # that were broken up. |
| 419 | for edge in list(self.dependencies): |
| 420 | if ( |
| 421 | None in edge |
| 422 | or edge[0].disabled |
| 423 | or edge[1].disabled |
| 424 | or cycles.issuperset(edge) |
| 425 | ): |
| 426 | self.dependencies.remove(edge) |
| 427 | elif edge[0] in cycles: |
| 428 | self.dependencies.remove(edge) |
| 429 | for dep in convert[edge[0]]: |
| 430 | self.dependencies.add((dep, edge[1])) |
| 431 | elif edge[1] in cycles: |
| 432 | self.dependencies.remove(edge) |
| 433 | for dep in convert[edge[1]]: |
| 434 | self.dependencies.add((edge[0], dep)) |
| 435 | |
| 436 | return { |
| 437 | a for a in self.postsort_actions.values() if not a.disabled |
| 438 | }.difference(cycles) |
| 439 | |
| 440 | def execute(self) -> None: |
| 441 | postsort_actions = self._generate_actions() |