I'm trying to make a threaded Tkinter app which uploads video to server, problem is that when I make threaded app, it ends in infinite loop. Here's the code:
class ThreadedTask(threading.Thread):
print "threaded task start"
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
def start_upload(self):
PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "upload_video_to_server.py"))
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
print filename
upload_video_to_server.make_Info(filename=filename, title=video_title, description=video_desc, tags=video_keywords)
upload_video_to_server.upload_Start(filename=filename)
print "ok"
else:
tkMessageBox.showerror(
"Error!",
"Unable to find upload script!"
)
return
def tb_click():
print "tbclick start"
progress()
prog_bar.start()
global queue
queue = Queue.Queue()
ThreadedTask(queue).start()
app.after(100, process_queue)
def process_queue():
try:
print "try pass"
msg = queue.get(0)
print "MSG: ", msg
prog_bar.stop()
except Queue.Empty:
print "Queue is empty!"
app.after(100, process_queue)
def progress():
global prog_bar
print "prog bar is being made"
prog_bar = ttk.Progressbar(
app, orient="horizontal",
length=200, mode="indeterminate"
)
prog_bar.pack(side=TOP)
button1 = Button(app, text="START", width=20, command=tb_click)
button1.place(x=355, y=420)
app.mainloop()
After running this code, I immediately get "threaded task start" printed out, and upon clicking "START" button I get into infinite loop printing "try pass" and "Queue is empty"... Just nothing (visible to end-user) happens when I click start button (video upload script isn't being run from this code)
What's wrong with this code? Is there something I missed?
Looks like start_upload
is never being executed. Try renaming it to run
. Then it will be executed when start()
is called.
You'll probably still get "Queue is empty" messages though, because you don't appear to ever add anything to the queue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.