Allows callbacks to work with nested schedulers. Callbacks will only be used by the first started scheduler they encounter. This means that only the outermost scheduler will use global callbacks.
(callbacks=None)
| 93 | |
| 94 | @contextmanager |
| 95 | def local_callbacks(callbacks=None): |
| 96 | """Allows callbacks to work with nested schedulers. |
| 97 | |
| 98 | Callbacks will only be used by the first started scheduler they encounter. |
| 99 | This means that only the outermost scheduler will use global callbacks.""" |
| 100 | global_callbacks = callbacks is None |
| 101 | if global_callbacks: |
| 102 | callbacks, Callback.active = Callback.active, set() |
| 103 | try: |
| 104 | yield callbacks or () |
| 105 | finally: |
| 106 | if global_callbacks: |
| 107 | Callback.active = callbacks |
| 108 | |
| 109 | |
| 110 | def normalize_callback(cb): |