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