Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
- Handled an issue where if chunk was too small due to division, it would throw an error
  • Loading branch information
7Zenox committed Jul 9, 2024
1 parent 40b07eb commit cdd8772
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pandarallel/progress_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from abc import ABC, abstractmethod
from enum import Enum
from itertools import count
from time import time_ns, sleep
from time import time_ns
import time
from typing import Callable, List, Union

from .utils import WorkerStatus
Expand Down Expand Up @@ -195,18 +196,18 @@ def progress_wrapper(
sleep_seconds: int = 0,
sleep_after_percent: float = 100.0
) -> Callable:
"""Wrap the function to apply in a function which monitors the part of work already
done and pauses after every n% completion.
"""Wrap the function to apply in a function which monitor the part of work already
done.
"""
counter = count()
state = ProgressState(chunk_size)
sleep_interval = int(chunk_size * (sleep_after_percent / 100.0))
sleep_after_iteration = max(int(chunk_size * (sleep_after_percent / 100.0)), 1) # Ensure at least 1

def closure(*user_defined_function_args, **user_defined_functions_kwargs):
iteration = next(counter)

if iteration % sleep_interval == 0 and iteration != 0:
sleep(sleep_seconds)
if iteration % sleep_after_iteration == 0: # Sleep every sleep_after_iteration
time.sleep(sleep_seconds)

if iteration == state.next_put_iteration:
time_now = time_ns()
Expand Down

0 comments on commit cdd8772

Please sign in to comment.