I'm working on Python 3.9, but I'm writing a program on tkinter and boto3.
It's a program for uploading simple files, but the problem is that I want to make a stop button when sending.
I tried to kill the thread, but An error occurs.
this is the button
self.thread_file = threading.Thread(target=self.defsend)
self.send_file = tk.Button(app,
text="send file(s)",
command=self.thread_file.start)
self.send_file.place(x=635, y=380)
self.thread_point = 0
this is the send function.
def defsend(self):
self.thread_point = 1
self.send_file.config(text='Stop')
filename = (self.file_list_box.get(0, tk.END))
self.item_qty = self.file_list_box.size()
self.item_run_qty = 0
try:
for filename_index in filename:
self.filename_index = filename_index
# ?? ??
config = TransferConfig(multipart_threshold=1024 * 25, max_concurrency=10,
multipart_chunksize=1024 * 25, use_threads=True)
bucket_name = '4by4inc-eu'
# ?? ?? ??? / s3??? ?? ?? ??
self.sendfilename = filename_index.rsplit('/', 1)
bucket_file = (self.aws_name + '/' + self.sendfilename[1])
self.item_run_qty = self.item_run_qty + 1
#?? ??? ?????.
test_1 = "Sending ..." + self.sendfilename[1]
self.log_list.insert(tk.END, test_1)
self.log_list.see("end")
self.percentage_1 = 0
###################################Here boto3!!!
#################################################
self.s3.upload_file(str(filename_index), str(bucket_name),
str(bucket_file), Config=config,
Callback=self.test_def)
#self.s3.upload_file(filename_index, bucket_name, bucket_file, Config=config, Callback=ProgressPercentage(filename_index))
test_1 = "( " + self.sendfilename[1] + " ) transfer complete."
self.log_list.insert(tk.END, test_1)
self.log_list.see("end")
paginator = self.s3.get_paginator('list_objects_v2')
response_iterator = paginator.paginate(
Bucket=self.bucket_name,
Prefix=self.aws_name
)
self.progressbar_label.config(text="Done")
self.file_list_box.delete(0, tk.END)
self.s3_list_box.delete(0, tk.END)
for page in response_iterator:
for content in page['Contents']:
self.s3_list_box.insert(tk.END, content['Key'])
self.send_file.config(state=tk.NORMAL, text='send file(s)')
except :
self.send_file.config(state=tk.NORMAL, text='send file(s)')
messagebox.showinfo("error", "Click the login button")
and this is progressbar
def test_def(self, bytes_amount):
#print("in")
#print(self.filename_index)
_size = float(os.path.getsize(self.filename_index))
_lock = threading.Lock()
_seen_so_far = 0
with _lock:
_seen_so_far += bytes_amount
percentage = (_seen_so_far / _size) * 100
#sys.stdout.write(
# "
%s %s / %s (%.2f%%)" % (
# self.filename_index, _seen_so_far, _size,
# percentage))
#sys.stdout.flush()
self.progressbar.step(percentage)
self.percentage_1 = self.percentage_1 + percentage
_on = int(self.percentage_1)
str(_on)
self.progressbar_label.config(text=str(_on)+"% "+"( " + str(self.item_run_qty) + "/" + str(self.item_qty) + " )")
I tried
"self.thread_file.daemon = True "
but I got an error.
Error: thread wasn't killed
What shoud i do?
question from:
https://stackoverflow.com/questions/65842631/want-to-stop-working-while-uploading-to-boto3 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…