Stop using as much closures
Use a custom tractor branch that fixes a `maybe_open_context` re entrant related bugsize_in_shm_token
							parent
							
								
									34fb497eb4
								
							
						
					
					
						commit
						e97dd1cbdb
					
				|  | @ -557,15 +557,9 @@ async def maybe_open_feed_handler() -> trio.abc.ReceiveStream: | |||
|         yield fh | ||||
| 
 | ||||
| 
 | ||||
| @acm | ||||
| async def open_price_feed( | ||||
|     instrument: str | ||||
| ) -> trio.abc.ReceiveStream: | ||||
| 
 | ||||
|     # XXX: hangs when going into this ctx mngr | ||||
|     async with maybe_open_feed_handler() as fh: | ||||
| 
 | ||||
|         async def relay( | ||||
| async def aio_price_feed_relay( | ||||
|     fh: FeedHandler, | ||||
|     instrument: Symbol, | ||||
|     from_trio: asyncio.Queue, | ||||
|     to_trio: trio.abc.SendChannel, | ||||
| ) -> None: | ||||
|  | @ -598,7 +592,7 @@ async def open_price_feed( | |||
|     fh.add_feed( | ||||
|         DERIBIT, | ||||
|         channels=[TRADES, L1_BOOK], | ||||
|                 symbols=[instrument], | ||||
|         symbols=[piker_sym_to_cb_sym(instrument)], | ||||
|         callbacks={ | ||||
|             TRADES: _trade, | ||||
|             L1_BOOK: _l1 | ||||
|  | @ -612,14 +606,19 @@ async def open_price_feed( | |||
|     # sync with trio | ||||
|     to_trio.send_nowait(None) | ||||
| 
 | ||||
|             try: | ||||
|     await asyncio.sleep(float('inf')) | ||||
| 
 | ||||
|             except asyncio.exceptions.CancelledError: | ||||
|                 ... | ||||
| 
 | ||||
| @acm | ||||
| async def open_price_feed( | ||||
|     instrument: str) -> trio.abc.ReceiveStream: | ||||
|     async with maybe_open_feed_handler() as fh: | ||||
|         async with to_asyncio.open_channel_from( | ||||
|             relay | ||||
|             partial( | ||||
|                 aio_price_feed_relay, | ||||
|                 fh, | ||||
|                 instrument | ||||
|             ) | ||||
|         ) as (first, chan): | ||||
|             yield chan | ||||
| 
 | ||||
|  | @ -642,14 +641,11 @@ async def maybe_open_price_feed( | |||
|         else: | ||||
|             yield feed | ||||
| 
 | ||||
| @acm | ||||
| async def open_order_feed( | ||||
|     instrument: List[str] | ||||
| ) -> trio.abc.ReceiveStream: | ||||
| 
 | ||||
|     async with maybe_open_feed_handler() as fh: | ||||
| 
 | ||||
|         async def relay( | ||||
| async def aio_order_feed_relay( | ||||
|     fh: FeedHandler, | ||||
|     instrument: Symbol, | ||||
|     from_trio: asyncio.Queue, | ||||
|     to_trio: trio.abc.SendChannel, | ||||
| ) -> None: | ||||
|  | @ -662,7 +658,7 @@ async def open_order_feed( | |||
|     fh.add_feed( | ||||
|         DERIBIT, | ||||
|         channels=[FILLS, ORDER_INFO], | ||||
|                 symbols=[instrument], | ||||
|         symbols=[instrument.upper()], | ||||
|         callbacks={ | ||||
|             FILLS: _fill, | ||||
|             ORDER_INFO: _order_info, | ||||
|  | @ -676,17 +672,24 @@ async def open_order_feed( | |||
|     # sync with trio | ||||
|     to_trio.send_nowait(None) | ||||
| 
 | ||||
|             try: | ||||
|     await asyncio.sleep(float('inf')) | ||||
| 
 | ||||
|             except asyncio.exceptions.CancelledError: | ||||
|                 ... | ||||
| 
 | ||||
| @acm | ||||
| async def open_order_feed( | ||||
|     instrument: List[str] | ||||
| ) -> trio.abc.ReceiveStream: | ||||
|     async with maybe_open_feed_handler() as fh: | ||||
|         async with to_asyncio.open_channel_from( | ||||
|             relay | ||||
|             partial( | ||||
|                 aio_order_feed_relay, | ||||
|                 fh, | ||||
|                 instrument | ||||
|             ) | ||||
|         ) as (first, chan): | ||||
|             yield chan | ||||
| 
 | ||||
| 
 | ||||
| @acm | ||||
| async def maybe_open_order_feed( | ||||
|     instrument: str | ||||
|  | @ -696,7 +699,8 @@ async def maybe_open_order_feed( | |||
|     async with maybe_open_context( | ||||
|         acm_func=open_order_feed, | ||||
|         kwargs={ | ||||
|             'instrument': instrument | ||||
|             'instrument': instrument, | ||||
|             'fh': fh | ||||
|         }, | ||||
|         key=f'{instrument}-order', | ||||
|     ) as (cache_hit, feed): | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| # we require a pinned dev branch to get some edge features that | ||||
| # are often untested in tractor's CI and/or being tested by us | ||||
| # first before committing as core features in tractor's base. | ||||
| -e git+https://github.com/goodboy/tractor.git@master#egg=tractor | ||||
| -e git+https://github.com/goodboy/tractor.git@reentrant_moc#egg=tractor | ||||
| 
 | ||||
| # `pyqtgraph` peeps keep breaking, fixing, improving so might as well | ||||
| # pin this to a dev branch that we have more control over especially | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue