import threading
import time
import os
event = threading.Event()
def walk(path):
event.wait()
try:
if os.path.isdir(path):
for file in os.listdir(path):
file_path = os.path.join(path, file)
for sub_file in walk(file_path):
yield sub_file
else:
yield path
except:
print "read file error!!"
def func():
for file in walk("/"):
print file
def test():
th2 = threading.Thread(target=func)
th2.setDaemon(True)
th2.start()
if __name__ == '__main__':
def btn_clicked(widget):
test()
print "start..."
def stop_btn_clicked(widget):
event.clear()
def start_btn_clicked(widget):
event.set()
import gtk
gtk.gdk.threads_init()
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.connect("destroy", lambda w : gtk.main_quit())
btn = gtk.Button("start thread")
btn.connect("clicked", btn_clicked)
stop_btn = gtk.Button("stop thread")
stop_btn.connect("clicked", stop_btn_clicked)
start_btn = gtk.Button("jxu start thread")
start_btn.connect("clicked", start_btn_clicked)
hbox = gtk.HBox()
hbox.pack_start(btn)
hbox.pack_start(stop_btn)
hbox.pack_start(start_btn)
win.add(hbox)
win.show_all()
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave()
import time
import os
event = threading.Event()
def walk(path):
event.wait()
try:
if os.path.isdir(path):
for file in os.listdir(path):
file_path = os.path.join(path, file)
for sub_file in walk(file_path):
yield sub_file
else:
yield path
except:
print "read file error!!"
def func():
for file in walk("/"):
print file
def test():
th2 = threading.Thread(target=func)
th2.setDaemon(True)
th2.start()
if __name__ == '__main__':
def btn_clicked(widget):
test()
print "start..."
def stop_btn_clicked(widget):
event.clear()
def start_btn_clicked(widget):
event.set()
import gtk
gtk.gdk.threads_init()
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.connect("destroy", lambda w : gtk.main_quit())
btn = gtk.Button("start thread")
btn.connect("clicked", btn_clicked)
stop_btn = gtk.Button("stop thread")
stop_btn.connect("clicked", stop_btn_clicked)
start_btn = gtk.Button("jxu start thread")
start_btn.connect("clicked", start_btn_clicked)
hbox = gtk.HBox()
hbox.pack_start(btn)
hbox.pack_start(stop_btn)
hbox.pack_start(start_btn)
win.add(hbox)
win.show_all()
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave()