def _capture(args: List[str]): api_caller = ApiCaller("https://api.lab-ml.com/api/v1/track?", {'run_uuid': generate_uuid()}) api_logs = ApiLogs() data = {'name': 'Capture', 'comment': ' '.join(args), 'time': time.time()} def _started(url): if url is None: return None logger.log([('Monitor experiment at ', Text.meta), (url, Text.link)]) webbrowser.open(url) api_caller.has_data(SimpleApiDataSource(data, callback=_started)) api_logs.set_api(api_caller, frequency=0) thread = ExecutorThread(' '.join(args), api_logs) thread.start() thread.join() data = { 'rank': 0, 'status': 'completed', 'details': None, 'time': time.time() } api_caller.has_data( SimpleApiDataSource({ 'status': data, 'time': time.time() })) api_caller.stop()
def _capture(args: List[str]): api_caller = ApiCaller("https://api.labml.ai/api/v1/track?", {'run_uuid': generate_uuid()}, timeout_seconds=120) api_logs = ApiLogs() data = { 'name': 'Capture', 'comment': ' '.join(args), 'time': time.time() } api_caller.add_handler(ApiUrlHandler(True, 'Monitor output at ')) api_caller.has_data(SimpleApiDataSource(data)) api_logs.set_api(api_caller, frequency=0) logger.log('Start capturing...', Text.meta) if args: thread = ExecutorThread(' '.join(args), api_logs) thread.start() thread.join() else: buffer = '' stdin = sys.stdin while stdin.readable(): data = stdin.read(1) if len(data) == 0: break print(data, end='') buffer += data if '\n' in buffer or len(buffer) > 100: api_logs.outputs(stdout_=buffer) buffer = '' if len(buffer) > 0: api_logs.outputs(stdout_=buffer) data = { 'rank': 0, 'status': 'completed', 'details': None, 'time': time.time() } api_caller.has_data(SimpleApiDataSource({ 'status': data, 'time': time.time() })) api_caller.stop()