pybiolib 1.2.1389__py3-none-any.whl → 1.2.1414__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pybiolib might be problematic. Click here for more details.

biolib/jobs/job.py CHANGED
@@ -26,7 +26,7 @@ from biolib.compute_node.utils import SystemExceptionCodeMap, SystemExceptionCod
26
26
  from biolib.jobs.job_result import JobResult
27
27
  from biolib.jobs.types import CloudJobDict, CloudJobStartedDict, JobDict
28
28
  from biolib.tables import BioLibTable
29
- from biolib.typing_utils import Dict, List, Optional, Union, cast
29
+ from biolib.typing_utils import Dict, Generator, List, Optional, Tuple, Union, cast
30
30
  from biolib.utils import IS_RUNNING_IN_NOTEBOOK
31
31
  from biolib.utils.app_uri import parse_app_uri
32
32
 
@@ -493,22 +493,11 @@ class Result:
493
493
  return Result(job_dict)
494
494
 
495
495
  @staticmethod
496
- def print_logs_packages(stdout_and_stderr_packages_b64):
496
+ def _yield_logs_packages(stdout_and_stderr_packages_b64) -> Generator[Tuple[str, bytes], None, None]:
497
497
  for stdout_and_stderr_package_b64 in stdout_and_stderr_packages_b64:
498
498
  stdout_and_stderr_package = base64.b64decode(stdout_and_stderr_package_b64)
499
499
  stdout_and_stderr = StdoutAndStderr(stdout_and_stderr_package).deserialize()
500
-
501
- if IS_RUNNING_IN_NOTEBOOK:
502
- sys.stdout.write(stdout_and_stderr.decode(encoding='utf-8', errors='replace'))
503
- else:
504
- sys.stdout.buffer.write(stdout_and_stderr)
505
- # Note: we avoid flush() in notebook as that breaks \r handling
506
- sys.stdout.buffer.flush()
507
- # flush after having processed all packages
508
- if IS_RUNNING_IN_NOTEBOOK:
509
- sys.stdout.flush()
510
- else:
511
- sys.stdout.buffer.flush()
500
+ yield ('stdout', stdout_and_stderr)
512
501
 
513
502
  def show(self) -> None:
514
503
  self._refetch_job_dict()
@@ -518,29 +507,44 @@ class Result:
518
507
  title=f'Result: {self._uuid}',
519
508
  ).print_table()
520
509
 
521
- def stream_logs(self) -> None:
510
+ def stream_logs(self, as_iterator: bool = False):
511
+ if as_iterator:
512
+ return self._iter_logs()
522
513
  self._stream_logs()
514
+ return None
523
515
 
524
516
  def _stream_logs(self, enable_print: bool = True) -> None:
517
+ try:
518
+ for stream_type, data in self._iter_logs(enable_print=enable_print):
519
+ if stream_type == 'stdout':
520
+ if IS_RUNNING_IN_NOTEBOOK:
521
+ sys.stdout.write(data.decode(encoding='utf-8', errors='replace'))
522
+ # Note: we avoid flush() in notebook as that breaks \r handling
523
+ else:
524
+ sys.stdout.buffer.write(data)
525
+ sys.stdout.buffer.flush()
526
+ elif stream_type == 'stderr':
527
+ if IS_RUNNING_IN_NOTEBOOK:
528
+ sys.stderr.write(data.decode(encoding='utf-8', errors='replace'))
529
+ # Note: we avoid flush() in notebook as that breaks \r handling
530
+ else:
531
+ sys.stderr.buffer.write(data)
532
+ sys.stderr.buffer.flush()
533
+ finally:
534
+ # Flush after having processed all packages
535
+ if IS_RUNNING_IN_NOTEBOOK:
536
+ sys.stdout.flush()
537
+ sys.stderr.flush()
538
+
539
+ def _iter_logs(self, enable_print: bool = True) -> Generator[Tuple[str, bytes], None, None]:
525
540
  try:
526
541
  cloud_job = self._get_cloud_job_awaiting_started()
527
542
  except CloudJobFinishedError:
528
543
  logger.info(f'--- The result {self.id} has already completed (no streaming will take place) ---')
529
544
  logger.info('--- The stdout log is printed below: ---')
530
- sys.stdout.flush()
531
- if IS_RUNNING_IN_NOTEBOOK:
532
- sys.stdout.write(self.get_stdout().decode(encoding='utf-8', errors='replace'))
533
- sys.stdout.flush()
534
- else:
535
- sys.stdout.buffer.write(self.get_stdout())
536
- sys.stdout.buffer.flush()
545
+ yield ('stdout', self.get_stdout())
537
546
  logger.info('--- The stderr log is printed below: ---')
538
- if IS_RUNNING_IN_NOTEBOOK:
539
- sys.stderr.write(self.get_stderr().decode(encoding='utf-8', errors='replace'))
540
- sys.stderr.flush()
541
- else:
542
- sys.stderr.buffer.write(self.get_stderr())
543
- sys.stderr.buffer.flush()
547
+ yield ('stderr', self.get_stderr())
544
548
  logger.info(f'--- The job {self.id} has already completed. Its output was printed above. ---')
545
549
  return
546
550
 
@@ -552,7 +556,7 @@ class Result:
552
556
  logger_no_user_data.debug(f'Using cloud proxy URL from env var BIOLIB_CLOUD_BASE_URL: {compute_node_url}')
553
557
 
554
558
  if enable_print:
555
- self._print_full_logs(node_url=compute_node_url)
559
+ yield from self._yield_full_logs(node_url=compute_node_url)
556
560
 
557
561
  final_status_messages: List[str] = []
558
562
  while True:
@@ -571,8 +575,8 @@ class Result:
571
575
  # Print the status before writing stdout and stderr
572
576
  logger.info(f'Cloud: {status_update["log_message"]}')
573
577
 
574
- if 'stdout_and_stderr_packages_b64' and enable_print:
575
- self.print_logs_packages(status_json['stdout_and_stderr_packages_b64'])
578
+ if enable_print:
579
+ yield from self._yield_logs_packages(status_json['stdout_and_stderr_packages_b64'])
576
580
 
577
581
  if 'error_code' in status_json:
578
582
  error_code = status_json['error_code']
@@ -589,7 +593,7 @@ class Result:
589
593
 
590
594
  self.wait() # Wait for compute node to tell the backend that the job is finished
591
595
 
592
- def _print_full_logs(self, node_url: str) -> None:
596
+ def _yield_full_logs(self, node_url: str) -> Generator[Tuple[str, bytes], None, None]:
593
597
  try:
594
598
  response_json = HttpClient.request(url=f'{node_url}/v1/job/{self._uuid}/status/?logs=full').json()
595
599
  except Exception as error:
@@ -599,7 +603,7 @@ class Result:
599
603
  for status_update in response_json.get('previous_status_updates', []):
600
604
  logger.info(f'Cloud: {status_update["log_message"]}')
601
605
 
602
- self.print_logs_packages(response_json['streamed_logs_packages_b64'])
606
+ yield from self._yield_logs_packages(response_json['streamed_logs_packages_b64'])
603
607
 
604
608
  def _get_cloud_job_awaiting_started(self) -> CloudJobStartedDict:
605
609
  retry_count = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybiolib
3
- Version: 1.2.1389
3
+ Version: 1.2.1414
4
4
  Summary: BioLib Python Client
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -145,7 +145,7 @@ biolib/compute_node/webserver/worker_thread.py,sha256=7uD9yQPhePYvP2HCJ27EeZ_h6p
145
145
  biolib/experiments/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
146
146
  biolib/experiments/experiment.py,sha256=ePipnJs6TW84jr9iBfYYRpYuEXUVGIxaD8Z8Jf0FYIA,13909
147
147
  biolib/jobs/__init__.py,sha256=aIb2H2DHjQbM2Bs-dysFijhwFcL58Blp0Co0gimED3w,32
148
- biolib/jobs/job.py,sha256=X7F_jCwAwtPcI1qu-oLamZNzt1IVSIeOPWlax1ztfAM,29674
148
+ biolib/jobs/job.py,sha256=3cUFo459O3Q3HDB3c6MTpJ-lDAyRsEi5cjnV6FA0W6g,30078
149
149
  biolib/jobs/job_result.py,sha256=Yl22Z8dc-8iKeC7Y4q7kgd08Ndajys1W1MsAbvE8wOA,5252
150
150
  biolib/jobs/types.py,sha256=rFs6bQWsNI-nb1Hu9QzOW2zFZ8bOVt7ax4UpGVASxVA,1034
151
151
  biolib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -161,8 +161,8 @@ biolib/utils/cache_state.py,sha256=u256F37QSRIVwqKlbnCyzAX4EMI-kl6Dwu6qwj-Qmag,3
161
161
  biolib/utils/multipart_uploader.py,sha256=XvGP1I8tQuKhAH-QugPRoEsCi9qvbRk-DVBs5PNwwJo,8452
162
162
  biolib/utils/seq_util.py,sha256=rImaghQGuIqTVWks6b9P2yKuN34uePUYPUFW_Wyoa4A,6737
163
163
  biolib/utils/zip/remote_zip.py,sha256=0wErYlxir5921agfFeV1xVjf29l9VNgGQvNlWOlj2Yc,23232
164
- pybiolib-1.2.1389.dist-info/METADATA,sha256=y8bhxtHgW135kkkPiKCE0WKPSZ4-DaEFS8aE9UAhmn0,1644
165
- pybiolib-1.2.1389.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
166
- pybiolib-1.2.1389.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
167
- pybiolib-1.2.1389.dist-info/licenses/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
168
- pybiolib-1.2.1389.dist-info/RECORD,,
164
+ pybiolib-1.2.1414.dist-info/METADATA,sha256=Tj71O4hNuExDxY_MTxPjDUPKqMmXQgTtC2M5tcauO8g,1644
165
+ pybiolib-1.2.1414.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
166
+ pybiolib-1.2.1414.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
167
+ pybiolib-1.2.1414.dist-info/licenses/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
168
+ pybiolib-1.2.1414.dist-info/RECORD,,