Cancellable tasks
All checks were successful
Gitea/kapitanbooru-uploader/pipeline/head This commit looks good
All checks were successful
Gitea/kapitanbooru-uploader/pipeline/head This commit looks good
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
# Klasa pomocnicza do monitorowania postępu uploadu
|
||||
class ProgressFile:
|
||||
def __init__(self, f, callback, total_size):
|
||||
def __init__(self, f, callback, total_size, cancel_event=None):
|
||||
self.f = f
|
||||
self.callback = callback
|
||||
self.cancel_event = cancel_event
|
||||
self.total_size = total_size
|
||||
self.read_bytes = 0
|
||||
|
||||
def read(self, size=-1):
|
||||
# Check for cancellation before reading more data
|
||||
if self.cancel_event is not None and self.cancel_event.is_set():
|
||||
raise Exception("Upload cancelled by user.")
|
||||
|
||||
data = self.f.read(size)
|
||||
self.read_bytes += len(data)
|
||||
self.callback(self.read_bytes, self.total_size)
|
||||
return data
|
||||
|
||||
def __getattr__(self, attr):
|
||||
return getattr(self.f, attr)
|
||||
return getattr(self.f, attr)
|
||||
|
Reference in New Issue
Block a user