@@ -146,9 +146,10 @@ async def __aexit__(self, exc_type, exc, tb):
146146
147147class MoveHubLaneProxy (object ):
148148
149- def __init__ (self , movehub , lane ):
149+ def __init__ (self , movehub , lane , identifier ):
150150 self .movehub = movehub
151151 self .lane = lane
152+ self .identifier = identifier
152153
153154 async def get_distance_async (self ):
154155 await self ._poll ()
@@ -420,7 +421,7 @@ def __init__(self, *args, **kwargs):
420421 self ._run_lock = asyncio .Lock ()
421422 self ._lane_locks = [asyncio .Lock () for i in range (self .n_lanes )]
422423
423- def run_async_program (self , program , lane = 0 , output = None ):
424+ def run_async_program (self , program , lane = 0 , output = None , identifier = identifier ):
424425
425426 if lane < 0 or lane >= self .n_lanes :
426427 raise RuntimeError (f"lane must be >=0 and < { self .n_lanes } but is { lane } " )
@@ -429,11 +430,11 @@ def run_async_program(self, program, lane=0, output=None):
429430 output = Output ()
430431 display (output )
431432 return asyncio .ensure_future (
432- self ._run_async_program (lane = lane , program = program , output = output )
433+ self ._run_async_program (lane = lane , program = program , output = output , identifier = identifier )
433434 )
434435
435436
436- def run_async_programs_concurrently (self , programs , output = None ):
437+ def run_async_programs_concurrently (self , programs , output = None , identifier = None ):
437438 if output is None :
438439 output = Output ()
439440 display (output )
@@ -443,8 +444,10 @@ def run_async_programs_concurrently(self, programs, output=None):
443444
444445 futures = []
445446 for lane , program in enumerate (programs ):
447+ if identifier is None :
448+ identifier = self .identifier
446449 f = asyncio .ensure_future (
447- self ._run_async_program (lane = lane , program = program , output = output )
450+ self ._run_async_program (lane = lane , program = program , output = output , identifier = identifier )
448451 )
449452 futures .append (f )
450453 return futures
@@ -460,13 +463,20 @@ def run_program(self, program, output=None):
460463 lane_proxy = MoveHubLaneProxy (movehub = self , lane = 0 )
461464 program (lane_proxy , output )
462465
463- def connect (self , output = None ):
464- async def main (lane , log ):
466+ def connect (self , output = None , identifier = None ):
467+ async def main (lane , log , identifier ):
465468 pass
469+ if output is None :
470+ output = Output ()
471+ display (output )
472+
473+ if identifier is None :
474+ identifier = self .identifier
466475
467- self .run_async_program (main , output = output )
476+ self .run_async_program (main , output = output , identifier = identifier )
477+
468478
469- async def _run_async_program (self , lane , program , output ):
479+ async def _run_async_program (self , lane , program , output , identifier ):
470480 def log (* args , ** kwargs ):
471481 old_stdout = sys .stdout
472482 sys .stdout = mystdout = StringIO ()
@@ -481,10 +491,10 @@ def log(*args, **kwargs):
481491 self ._log = log
482492
483493 async with self ._lane_locks [lane ]:
484- lane_proxy = MoveHubLaneProxy (movehub = self , lane = lane )
494+ lane_proxy = MoveHubLaneProxy (movehub = self , lane = lane , identifier = identifier )
485495 try :
486496 await lane_proxy ._connect ()
487- await program (lane_proxy , log )
497+ await program (lane_proxy , log , identifier )
488498 except Exception as ex :
489499 err_str = "" .join (
490500 traceback .TracebackException .from_exception (ex ).format ()
0 commit comments