Skip to content

Commit 1fd19fd

Browse files
author
henrique
committed
minor logger refactor
1 parent 17ba6a6 commit 1fd19fd

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

src/codeevolve/runner.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def _cleanup_on_signal(signum: int, frame: Any) -> None:
8585
_cleanup_state["cleaned_up"] = True
8686

8787
signal_name: str = signal.Signals(signum).name
88-
print(f"\n\nReceived {signal_name}. Shutting down...", file=sys.stderr)
8988

9089
processes: List[mp.Process] = _cleanup_state["processes"]
9190
_terminate_processes(processes)
@@ -103,7 +102,6 @@ def _cleanup_on_signal(signum: int, frame: Any) -> None:
103102
if directory_lock:
104103
directory_lock.release()
105104

106-
print("Cleanup complete.", file=sys.stderr)
107105
sys.exit(128 + signum)
108106

109107

@@ -363,15 +361,14 @@ def monitor_island_processes(
363361
)
364362
_write_crash_summary(out_dir, i, process.exitcode, error_msg, time)
365363

366-
print(f"\n{'='*60}", file=sys.stderr)
367-
print(f"ERROR: {error_msg}", file=sys.stderr)
364+
print(f"\n{'=' * 46} ERROR {'=' * 47}", file=sys.stderr)
365+
print(f"{error_msg}", file=sys.stderr)
368366
print(
369367
f"See {out_dir}/{CRASH_LOG_FILE.format(time=time)} and island logs for details.",
370368
file=sys.stderr,
371369
)
372-
print(f"{'='*60}\n", file=sys.stderr)
370+
print(f"{'='*100}\n", file=sys.stderr)
373371

374-
print("Terminating all remaining islands...", file=sys.stderr)
375372
other_processes: List[mp.Process] = [
376373
other_process
377374
for j, other_process in enumerate(processes)
@@ -380,14 +377,14 @@ def monitor_island_processes(
380377
_terminate_processes(processes=other_processes)
381378

382379
return 1
383-
384-
print("\nAll islands completed successfully.")
380+
381+
cleanup_log_daemon(log_daemon, global_data.log_queue)
382+
print("=" * 45 + " FINISHED " + "=" * 45)
385383
return 0
386384

387385
except KeyboardInterrupt:
388386
cleanup_log_daemon(log_daemon, global_data.log_queue)
389387

390-
print("\n\nKeyboard interrupt received. Shutting down islands...", file=sys.stderr)
391388
_terminate_processes(processes)
392389

393390
directory_lock: Optional[DirectoryLock] = _cleanup_state.get("directory_lock")

src/codeevolve/utils/logging.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def _print_global_status(args: Dict[str, Any], global_data: GlobalSyncData) -> N
250250
elapsed_str: str = format_elapsed_time(elapsed)
251251
print("=" * 100)
252252
print(ASCII_NAME)
253-
print("=" * 46 + " INFO " + "=" * 46)
253+
print("=" * 47 + " INFO " + "=" * 47)
254254
print(f"> INPT DIR = {args['inpt_dir']}")
255255
print(f"> CFG PATH = {args['cfg_path']}")
256256
print(f"> OUT DIR = {args['out_dir']}")
@@ -296,7 +296,6 @@ def cli_logger(
296296
if message is None:
297297
os.system("cls" if os.name == "nt" else "clear")
298298
_print_global_status(args, global_data)
299-
print("=" * 45 + " FINISHED " + "=" * 45)
300299
return
301300

302301
match = island_id_pattern.search(message)
@@ -315,13 +314,11 @@ def cli_logger(
315314
os.system("cls" if os.name == "nt" else "clear")
316315

317316
_print_global_status(args, global_data)
318-
print("=" * 46 + " LOGS " + "=" * 46)
317+
print("=" * 47 + " LOGS " + "=" * 47)
319318
for i in sorted(island_logs.keys()):
320-
current_epoch = island_epochs.get(i, "N/A")
319+
current_epoch = island_epochs.get(i, "?")
321320
print(f"=== ISLAND {i} | EPOCH {current_epoch} ===")
322-
if not island_logs[i]:
323-
print("(Waiting for messages...)")
324-
else:
321+
if island_logs[i] is not None:
325322
for msg in island_logs[i]:
326323
print(f" > {msg}")
327324
print("-" * 45)

0 commit comments

Comments
 (0)