Adjust to `trio`'s strict eg nurseries throughout!
Using `tractor.trionics.collapse_eg()` as needed to avoid, at the least, crash-worthy (in debug-mode REPL-ing terms) nested cancellation egs that exhibit on SIGINT/ctl-c of each "app" (chart & daemon). Also a bit of renaming of all `trio.Nursery`s to `tn`, the new "task nursery" shorthand-var-name being used in all our other `tractor` related projects.port_to_latest_tractor
							parent
							
								
									baff466ee0
								
							
						
					
					
						commit
						f50202a6af
					
				|  | @ -96,7 +96,10 @@ async def _setup_persistent_brokerd( | ||||||
|     # - `open_symbol_search()` |     # - `open_symbol_search()` | ||||||
|     # NOTE: see ep invocation details inside `.data.feed`. |     # NOTE: see ep invocation details inside `.data.feed`. | ||||||
|     try: |     try: | ||||||
|         async with trio.open_nursery() as service_nursery: |         async with ( | ||||||
|  |             tractor.trionics.collapse_eg(), | ||||||
|  |             trio.open_nursery() as service_nursery | ||||||
|  |         ): | ||||||
|             bus: _FeedsBus = feed.get_feed_bus( |             bus: _FeedsBus = feed.get_feed_bus( | ||||||
|                 brokername, |                 brokername, | ||||||
|                 service_nursery, |                 service_nursery, | ||||||
|  |  | ||||||
|  | @ -25,7 +25,10 @@ from typing import TYPE_CHECKING | ||||||
| 
 | 
 | ||||||
| import trio | import trio | ||||||
| import tractor | import tractor | ||||||
| from tractor.trionics import broadcast_receiver | from tractor.trionics import ( | ||||||
|  |     broadcast_receiver, | ||||||
|  |     collapse_eg, | ||||||
|  | ) | ||||||
| 
 | 
 | ||||||
| from ._util import ( | from ._util import ( | ||||||
|     log,  # sub-sys logger |     log,  # sub-sys logger | ||||||
|  | @ -281,8 +284,11 @@ async def open_ems( | ||||||
|             client._ems_stream = trades_stream |             client._ems_stream = trades_stream | ||||||
| 
 | 
 | ||||||
|             # start sync code order msg delivery task |             # start sync code order msg delivery task | ||||||
|             async with trio.open_nursery() as n: |             async with ( | ||||||
|                 n.start_soon( |                 collapse_eg(), | ||||||
|  |                 trio.open_nursery() as tn, | ||||||
|  |             ): | ||||||
|  |                 tn.start_soon( | ||||||
|                     relay_orders_from_sync_code, |                     relay_orders_from_sync_code, | ||||||
|                     client, |                     client, | ||||||
|                     fqme, |                     fqme, | ||||||
|  | @ -298,4 +304,4 @@ async def open_ems( | ||||||
|                 ) |                 ) | ||||||
| 
 | 
 | ||||||
|                 # stop the sync-msg-relay task on exit. |                 # stop the sync-msg-relay task on exit. | ||||||
|                 n.cancel_scope.cancel() |                 tn.cancel_scope.cancel() | ||||||
|  |  | ||||||
|  | @ -498,6 +498,7 @@ async def cascade( | ||||||
| 
 | 
 | ||||||
|         func_name: str = func.__name__ |         func_name: str = func.__name__ | ||||||
|         async with ( |         async with ( | ||||||
|  |             tractor.trionics.collapse_eg(),  # avoid multi-taskc tb in console | ||||||
|             trio.open_nursery() as tn, |             trio.open_nursery() as tn, | ||||||
|         ): |         ): | ||||||
|             # TODO: might be better to just make a "restart" method where |             # TODO: might be better to just make a "restart" method where | ||||||
|  |  | ||||||
|  | @ -200,7 +200,8 @@ async def open_pikerd( | ||||||
|             reg_addrs, |             reg_addrs, | ||||||
|         ), |         ), | ||||||
|         tractor.open_nursery() as actor_nursery, |         tractor.open_nursery() as actor_nursery, | ||||||
|         trio.open_nursery() as service_nursery, |         tractor.trionics.collapse_eg(), | ||||||
|  |         trio.open_nursery() as service_tn, | ||||||
|     ): |     ): | ||||||
|         for addr in reg_addrs: |         for addr in reg_addrs: | ||||||
|             if addr not in root_actor.accept_addrs: |             if addr not in root_actor.accept_addrs: | ||||||
|  | @ -211,7 +212,7 @@ async def open_pikerd( | ||||||
| 
 | 
 | ||||||
|         # assign globally for future daemon/task creation |         # assign globally for future daemon/task creation | ||||||
|         Services.actor_n = actor_nursery |         Services.actor_n = actor_nursery | ||||||
|         Services.service_n = service_nursery |         Services.service_n = service_tn | ||||||
|         Services.debug_mode = debug_mode |         Services.debug_mode = debug_mode | ||||||
| 
 | 
 | ||||||
|         try: |         try: | ||||||
|  | @ -221,7 +222,7 @@ async def open_pikerd( | ||||||
|             # TODO: is this more clever/efficient? |             # TODO: is this more clever/efficient? | ||||||
|             # if 'samplerd' in Services.service_tasks: |             # if 'samplerd' in Services.service_tasks: | ||||||
|             #     await Services.cancel_service('samplerd') |             #     await Services.cancel_service('samplerd') | ||||||
|             service_nursery.cancel_scope.cancel() |             service_tn.cancel_scope.cancel() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # TODO: do we even need this? | # TODO: do we even need this? | ||||||
|  |  | ||||||
|  | @ -21,6 +21,7 @@ Main app startup and run. | ||||||
| from functools import partial | from functools import partial | ||||||
| from types import ModuleType | from types import ModuleType | ||||||
| 
 | 
 | ||||||
|  | import tractor | ||||||
| import trio | import trio | ||||||
| 
 | 
 | ||||||
| from piker.ui.qt import ( | from piker.ui.qt import ( | ||||||
|  | @ -116,6 +117,7 @@ async def _async_main( | ||||||
|         needed_brokermods[brokername] = brokers[brokername] |         needed_brokermods[brokername] = brokers[brokername] | ||||||
| 
 | 
 | ||||||
|     async with ( |     async with ( | ||||||
|  |         tractor.trionics.collapse_eg(), | ||||||
|         trio.open_nursery() as root_n, |         trio.open_nursery() as root_n, | ||||||
|     ): |     ): | ||||||
|         # set root nursery and task stack for spawning other charts/feeds |         # set root nursery and task stack for spawning other charts/feeds | ||||||
|  |  | ||||||
|  | @ -33,7 +33,6 @@ import trio | ||||||
| 
 | 
 | ||||||
| from piker.ui.qt import ( | from piker.ui.qt import ( | ||||||
|     QtCore, |     QtCore, | ||||||
|     QtWidgets, |  | ||||||
|     Qt, |     Qt, | ||||||
|     QLineF, |     QLineF, | ||||||
|     QFrame, |     QFrame, | ||||||
|  |  | ||||||
|  | @ -1445,7 +1445,10 @@ async def display_symbol_data( | ||||||
|         # for pause/resume on mouse interaction |         # for pause/resume on mouse interaction | ||||||
|         rt_chart.feed = feed |         rt_chart.feed = feed | ||||||
| 
 | 
 | ||||||
|         async with trio.open_nursery() as ln: |         async with ( | ||||||
|  |             tractor.trionics.collapse_eg(), | ||||||
|  |             trio.open_nursery() as ln, | ||||||
|  |         ): | ||||||
|             # if available load volume related built-in display(s) |             # if available load volume related built-in display(s) | ||||||
|             vlm_charts: dict[ |             vlm_charts: dict[ | ||||||
|                 str, |                 str, | ||||||
|  |  | ||||||
|  | @ -22,7 +22,10 @@ from contextlib import asynccontextmanager as acm | ||||||
| from typing import Callable | from typing import Callable | ||||||
| 
 | 
 | ||||||
| import trio | import trio | ||||||
| from tractor.trionics import gather_contexts | from tractor.trionics import ( | ||||||
|  |     gather_contexts, | ||||||
|  |     collapse_eg, | ||||||
|  | ) | ||||||
| 
 | 
 | ||||||
| from piker.ui.qt import ( | from piker.ui.qt import ( | ||||||
|     QtCore, |     QtCore, | ||||||
|  | @ -207,7 +210,10 @@ async def open_signal_handler( | ||||||
|         async for args in recv: |         async for args in recv: | ||||||
|             await async_handler(*args) |             await async_handler(*args) | ||||||
| 
 | 
 | ||||||
|     async with trio.open_nursery() as tn: |     async with ( | ||||||
|  |         collapse_eg(), | ||||||
|  |         trio.open_nursery() as tn | ||||||
|  |     ): | ||||||
|         tn.start_soon(proxy_to_handler) |         tn.start_soon(proxy_to_handler) | ||||||
|         async with send: |         async with send: | ||||||
|             yield |             yield | ||||||
|  | @ -242,6 +248,7 @@ async def open_handlers( | ||||||
|     widget: QWidget |     widget: QWidget | ||||||
|     streams: list[trio.abc.ReceiveChannel] |     streams: list[trio.abc.ReceiveChannel] | ||||||
|     async with ( |     async with ( | ||||||
|  |         collapse_eg(), | ||||||
|         trio.open_nursery() as tn, |         trio.open_nursery() as tn, | ||||||
|         gather_contexts([ |         gather_contexts([ | ||||||
|             open_event_stream( |             open_event_stream( | ||||||
|  |  | ||||||
|  | @ -600,6 +600,7 @@ async def open_fsp_admin( | ||||||
|             kwargs=kwargs, |             kwargs=kwargs, | ||||||
|         ) as (cache_hit, cluster_map), |         ) as (cache_hit, cluster_map), | ||||||
| 
 | 
 | ||||||
|  |         tractor.trionics.collapse_eg(), | ||||||
|         trio.open_nursery() as tn, |         trio.open_nursery() as tn, | ||||||
|     ): |     ): | ||||||
|         if cache_hit: |         if cache_hit: | ||||||
|  | @ -613,6 +614,8 @@ async def open_fsp_admin( | ||||||
|         ) |         ) | ||||||
|         try: |         try: | ||||||
|             yield admin |             yield admin | ||||||
|  | 
 | ||||||
|  |         # ??TODO, does this *need* to be inside a finally? | ||||||
|         finally: |         finally: | ||||||
|             # terminate all tasks via signals |             # terminate all tasks via signals | ||||||
|             for key, entry in admin._registry.items(): |             for key, entry in admin._registry.items(): | ||||||
|  |  | ||||||
|  | @ -792,6 +792,7 @@ async def open_order_mode( | ||||||
|             brokerd_accounts, |             brokerd_accounts, | ||||||
|             ems_dialog_msgs, |             ems_dialog_msgs, | ||||||
|         ), |         ), | ||||||
|  |         tractor.trionics.collapse_eg(), | ||||||
|         trio.open_nursery() as tn, |         trio.open_nursery() as tn, | ||||||
| 
 | 
 | ||||||
|     ): |     ): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue