R
R
Ruben Harutyunov2014-02-15 19:17:47
Python
Ruben Harutyunov, 2014-02-15 19:17:47

Python. How to implement program reuse without restart?

Hello, I wrote this code:

# -*- coding: utf-8 -*-
from Tkinter import *
import urllib, ttk, tkMessageBox
from threading import Thread
from Queue import Queue
queue = Queue()
def func():
    arc1 = c1.get()
    arc2 = c2.get()
    def downloader(url,file):
        urllib.urlretrieve(url, file)
        queue.put(True)

    if arc1 == 1:
        downloader('http://cs1632v4.vk.me/u222124/audios/88970df3fe1f.mp3','file1.mp3')
    if arc2 == 1:
        downloader('http://cs536301v4.vk.me/u131194151/audios/bc2867aeb217.mp3','file2.mp3')

th = Thread(target=func, args=())
def starter(event):
    th.start()
    pb.pack()
    pb.start()
root = Tk()
def task():
    try:
        q = queue.get_nowait()
    except:
        q = False
    if q:
        tkMessageBox.showinfo('Done')
    root.after(1000, task)
root.after(1000, task)
c1 = IntVar()
c2 = IntVar()
chk1 = Checkbutton(root, text = '1', onvalue = 1, offvalue = 0, variable = c1)
chk2 = Checkbutton(root, text = '2', onvalue = 1, offvalue = 0, variable = c2)
pb = ttk.Progressbar(length=200, orient='horizontal', mode='indeterminate')
but = Button(root, text = 'Go!')
root.minsize(width=400, height=350)
but.bind('<Button-1>', starter)
but.pack()
chk1.pack()
chk2.pack()
root.mainloop()

This code works, but the fact is that it is required to be able to use the program again (for example, after downloading the first file, download the second one). Now this is not possible due to the fact that streams can only be used once. How to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maxaon, 2014-02-16
@K_DOT

Look towards multiprocessing.Pool

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question