Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25059
| From | "self.python" <howmuchistoday@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | how can I make it work? |
| Date | 2012-07-08 19:02 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <dbe3aa14-2a4f-4d54-972a-dbb30029db4f@km7g2000pbc.googlegroups.com> (permalink) |
it's a finder using threading to accelerate but it never works..
and I have no idea why it doesn't work:(
it doesn't work too after changing threading to multiprocessing..
how can I make it work? or at least I know what's the problem...
plz help the poor newbie...
import os,threading,multiprocessing
def finder(path,q):
for x in os.walk(unicode(path)):
if x[1]:
for dirname in x[1]:
if target in dirname.lower():
q.put(os.path.join(x[0],dirname))
if x[2]:
for name in x[2]:
if target in name.lower():
q.put(os.path.join(x[0],name))
q.put(1)
def printer(q):
cmd=0
while 1:
tmp=q.get()
if tmp==1:
cmd += 1
continue
if cmd ==thnum:
break
print tmp
if __name__ =="__main__":
q=multiprocessing.JoinableQueue()
ini=os.walk(u"C:\\").next()
thnum=len(ini[1])
target=raw_input("what you wanna get\n")
p=multiprocessing.Process(target=printer,args=(q,))
p.daemon=1
p.start()
for i in xrange(thnum):
t=threading.Thread(target=finder,args=(ini[1][i],q,))
t.start()
print i," started"
q.join()
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
how can I make it work? "self.python" <howmuchistoday@gmail.com> - 2012-07-08 19:02 -0700
Re: how can I make it work? MRAB <python@mrabarnett.plus.com> - 2012-07-09 03:20 +0100
Re: how can I make it work? "self.python" <howmuchistoday@gmail.com> - 2012-07-08 19:41 -0700
Re: how can I make it work? "self.python" <howmuchistoday@gmail.com> - 2012-07-08 20:29 -0700
Re: how can I make it work? Terry Reedy <tjreedy@udel.edu> - 2012-07-09 02:05 -0400
csiph-web