Always print progress bar at 100%

This commit is contained in:
Davte 2020-04-19 20:41:36 +02:00
parent dc596cfac6
commit 063cc375df
4 changed files with 10 additions and 6 deletions

View File

@ -13,6 +13,6 @@ __author__ = "Davide Testa"
__email__ = "davide@davte.it"
__credits__ = []
__license__ = "GNU General Public License v3.0"
__version__ = "0.0.8"
__version__ = "0.0.9"
__maintainer__ = "Davide Testa"
__contact__ = "t.me/davte"

View File

@ -399,6 +399,7 @@ class Client:
self.print_progress_bar(
progress=new_progress,
bytes_=bytes_sent,
force=(new_progress == 100)
)
print() # New line after progress_bar
writer.close()
@ -431,7 +432,8 @@ class Client:
)
self.print_progress_bar(
progress=new_progress,
bytes_=bytes_received
bytes_=bytes_received,
force=(new_progress == 100)
)
if not input_data:
break

View File

@ -73,7 +73,7 @@ class Server:
def set_ssl_context(self, ssl_context: ssl.SSLContext):
self._ssl_context = ssl_context
async def run_reader(self, reader, connection_token):
async def run_reader(self, reader: asyncio.StreamReader, connection_token):
while 1:
try:
# Wait one second if buffer is full
@ -90,7 +90,7 @@ class Server:
except Exception as e:
logging.error(f"Unexpected exception:\n{e}", exc_info=True)
async def run_writer(self, writer, connection_token):
async def run_writer(self, writer: asyncio.StreamWriter, connection_token):
consecutive_interruptions = 0
errors = 0
while connection_token in self.buffers:
@ -100,6 +100,7 @@ class Server:
# Slow down if buffer is empty; after 1.5 s of silence, break
consecutive_interruptions += 1
if consecutive_interruptions > 3:
logging.error("Too many interruptions...")
break
await asyncio.sleep(.5)
continue
@ -166,6 +167,7 @@ class Server:
else:
return 0 # On success, return 0
# On exception, disconnect and return 1
logging.error("Disconnecting...")
self.disconnect(connection_token=connection_token)
return 1

View File

@ -77,9 +77,9 @@ def timed_action(interval: Union[int, float, datetime.timedelta] = None):
timedelta = interval
def timer(function_to_time):
def timed_function(*args, **kwargs):
def timed_function(*args, force: bool = False, **kwargs):
nonlocal last_call
if now() > last_call + timedelta:
if force or now() > last_call + timedelta:
last_call = now()
return function_to_time(*args, **kwargs)
return