Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25059 > unrolled thread
| Started by | "self.python" <howmuchistoday@gmail.com> |
|---|---|
| First post | 2012-07-08 19:02 -0700 |
| Last post | 2012-07-09 02:05 -0400 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | "self.python" <howmuchistoday@gmail.com> |
|---|---|
| Date | 2012-07-08 19:02 -0700 |
| Subject | how can I make it work? |
| Message-ID | <dbe3aa14-2a4f-4d54-972a-dbb30029db4f@km7g2000pbc.googlegroups.com> |
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()
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2012-07-09 03:20 +0100 |
| Message-ID | <mailman.1931.1341800462.4697.python-list@python.org> |
| In reply to | #25059 |
On 09/07/2012 03:02, self.python wrote: > 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... > [snip] It would help if you gave more information than just "it doesn't work". In what way doesn't it work?
[toc] | [prev] | [next] | [standalone]
| From | "self.python" <howmuchistoday@gmail.com> |
|---|---|
| Date | 2012-07-08 19:41 -0700 |
| Message-ID | <9ba56ed1-c5fd-4048-8287-f55b16aed50f@googlegroups.com> |
| In reply to | #25059 |
2012년 7월 9일 월요일 오전 11시 2분 41초 UTC+9, self.python 님의 말:
> 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()
It shows
0 started
1 started
...
22 started
but then it show nothing
the cursur blinks continuously
but the result never printed(maybe not produces?)
[toc] | [prev] | [next] | [standalone]
| From | "self.python" <howmuchistoday@gmail.com> |
|---|---|
| Date | 2012-07-08 20:29 -0700 |
| Message-ID | <0e3be23f-9db9-48f0-840e-058d7f85573f@googlegroups.com> |
| In reply to | #25062 |
2012년 7월 9일 월요일 오전 11시 41분 32초 UTC+9, self.python 님의 말:
> 2012년 7월 9일 월요일 오전 11시 2분 41초 UTC+9, self.python 님의 말:
> > 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()
>
>
> It shows
> 0 started
> 1 started
> ...
> 22 started
> but then it show nothing
> the cursur blinks continuously
> but the result never printed(maybe not produces?)
I knew what's the problem on other site.
It just because I miss to send the full path to each thread...
what an idiot..
but I'm still wondering that there is any good way
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2012-07-09 02:05 -0400 |
| Message-ID | <mailman.1934.1341813939.4697.python-list@python.org> |
| In reply to | #25059 |
On 7/8/2012 10:02 PM, self.python wrote: > it's a finder using threading to accelerate Threading with Python does not accelerate unless all but one of the treads are i/o bound. You need multiple processes to use multiple cores in parallel. -- Terry Jan Reedy
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web