From 864b3ba18738c8f983037bb3a0b44840356eb444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sierro?= Date: Tue, 6 Feb 2024 09:39:36 +0100 Subject: [PATCH] removed stdout redirection for now --- examples/show_multi_bar.py | 4 ++-- src/scgenerator/threading.py | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/examples/show_multi_bar.py b/examples/show_multi_bar.py index 4ed2d91..c415d87 100644 --- a/examples/show_multi_bar.py +++ b/examples/show_multi_bar.py @@ -10,8 +10,8 @@ def compute_stuff(num: int, pbar: sc.threading.Multibar): speed = random.random() * 5 for i in pbar(range(SIZE), desc=f"num {num}"): time.sleep(0.05 * speed * random.random()) - if random.random() > 0.98: - print(f"some text {i}") + # if random.random() > 0.98: + # print(f"some text {i}") def main(): diff --git a/src/scgenerator/threading.py b/src/scgenerator/threading.py index f6e295e..eb11f77 100644 --- a/src/scgenerator/threading.py +++ b/src/scgenerator/threading.py @@ -1,17 +1,16 @@ from __future__ import annotations import multiprocessing +import sys from collections.abc import Iterable, Iterator from dataclasses import dataclass from enum import Enum, auto from multiprocessing import Queue from threading import Lock, Thread -from typing import NamedTuple, TypeVar, Callable, Any +from typing import Any, Callable, NamedTuple, TypeVar from tqdm import tqdm -import sys - T = TypeVar("T") @@ -105,7 +104,7 @@ class PositionGetter: def __init__(self, n_tot: int, n: int, offset: int = 0): self.remaining = n_tot self.offset = offset - self.busy_at = [False for _ in range(n_tot)] + self.busy_at = [False for _ in range(n)] @property def max_pos(self) -> int: @@ -217,12 +216,12 @@ class Multibar: self.current = start self.queue = queue self.finished = False - self.stdout = QueueStdOut(self.id, self.queue) + # self.stdout = QueueStdOut(self.id, self.queue) - sys.stdout = self.stdout - sys.stderr = self.stdout + # sys.stdout = self.stdout + # sys.stderr = self.stdout - print(sys.stdout, file=sys.__stdout__) + # print(sys.stdout, file=sys.__stdout__) def update(self, amount: float | int = 1): self.check_start_finish() @@ -234,8 +233,8 @@ class Multibar: def close(self): self.queue.put(PBarMessage(self.id, Command.FINISHED)) - sys.stdout = sys.__stdout__ - sys.stderr = sys.__stderr__ + # sys.stdout = sys.__stdout__ + # sys.stderr = sys.__stderr__ def __enter__(self): return self