@@ -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 ()
@@ -411,6 +412,7 @@ class MoveHubWidget(DOMWidget):
411412 _view_module_version = Unicode (module_version ).tag (sync = True )
412413 _device_info = Dict (DEFAULT_DEVICE_INFO , read_only = True ).tag (sync = True )
413414 name = Unicode ("device1" ).tag (sync = True )
415+ identifier = Unicode ("" ).tag (sync = True )
414416 n_lanes = Int (3 ).tag (sync = True )
415417
416418 def __init__ (self , * args , ** kwargs ):
@@ -419,7 +421,7 @@ def __init__(self, *args, **kwargs):
419421 self ._run_lock = asyncio .Lock ()
420422 self ._lane_locks = [asyncio .Lock () for i in range (self .n_lanes )]
421423
422- def run_async_program (self , program , lane = 0 , output = None ):
424+ def run_async_program (self , program , lane = 0 , output = None , identifier = identifier ):
423425
424426 if lane < 0 or lane >= self .n_lanes :
425427 raise RuntimeError (f"lane must be >=0 and < { self .n_lanes } but is { lane } " )
@@ -428,11 +430,11 @@ def run_async_program(self, program, lane=0, output=None):
428430 output = Output ()
429431 display (output )
430432 return asyncio .ensure_future (
431- self ._run_async_program (lane = lane , program = program , output = output )
433+ self ._run_async_program (lane = lane , program = program , output = output , identifier = identifier )
432434 )
433435
434436
435- def run_async_programs_concurrently (self , programs , output = None ):
437+ def run_async_programs_concurrently (self , programs , output = None , identifier = None ):
436438 if output is None :
437439 output = Output ()
438440 display (output )
@@ -442,8 +444,10 @@ def run_async_programs_concurrently(self, programs, output=None):
442444
443445 futures = []
444446 for lane , program in enumerate (programs ):
447+ if identifier is None :
448+ identifier = self .identifier
445449 f = asyncio .ensure_future (
446- self ._run_async_program (lane = lane , program = program , output = output )
450+ self ._run_async_program (lane = lane , program = program , output = output , identifier = identifier )
447451 )
448452 futures .append (f )
449453 return futures
@@ -459,13 +463,20 @@ def run_program(self, program, output=None):
459463 lane_proxy = MoveHubLaneProxy (movehub = self , lane = 0 )
460464 program (lane_proxy , output )
461465
462- def connect (self , output = None ):
463- async def main (lane , log ):
466+ def connect (self , output = None , identifier = None ):
467+ async def main (lane , log , identifier ):
464468 pass
469+ if output is None :
470+ output = Output ()
471+ display (output )
472+
473+ if identifier is None :
474+ identifier = self .identifier
465475
466- self .run_async_program (main , output = output )
476+ self .run_async_program (main , output = output , identifier = identifier )
477+
467478
468- async def _run_async_program (self , lane , program , output ):
479+ async def _run_async_program (self , lane , program , output , identifier ):
469480 def log (* args , ** kwargs ):
470481 old_stdout = sys .stdout
471482 sys .stdout = mystdout = StringIO ()
@@ -480,10 +491,10 @@ def log(*args, **kwargs):
480491 self ._log = log
481492
482493 async with self ._lane_locks [lane ]:
483- lane_proxy = MoveHubLaneProxy (movehub = self , lane = lane )
494+ lane_proxy = MoveHubLaneProxy (movehub = self , lane = lane , identifier = identifier )
484495 try :
485496 await lane_proxy ._connect ()
486- await program (lane_proxy , log )
497+ await program (lane_proxy , log , identifier )
487498 except Exception as ex :
488499 err_str = "" .join (
489500 traceback .TracebackException .from_exception (ex ).format ()
0 commit comments