Article View: pl.comp.lang.python
Article #27316Re: jak sensownie polaczyc watki z rekurencja?
From: Slawomir Piasecki
Date: Thu, 25 Feb 2010 16:52
Date: Thu, 25 Feb 2010 16:52
67 lines
3142 bytes
3142 bytes
ok wiec multiprocess, poczytalem troche dokumentacji i troche
tutoriali
i postanowilem wypisac wstepnie maly programik:
[code]
def f(q, n):
for i in range(2,4):
t = i * n
if t < 100:
print "dodaje ", t
q.put(t) # dodaj do kolejki
def run(nrStart):
q = Queue()
for i in range(nrStart):
q.put(i) # dodaj do kolejki
nr = 2
pula = []
while True:
for i in pula:
if i.is_alive() is False:
pula.remove(i) # usun z puli jesli juz wykonany
while len(pula) < nr:
if q.qsize() > 0:
dat = q.get() # pobierz z kolejki
print "startuje ", dat
p = Process(target=f, args=(q, dat)).start() # wystartuj
z procesem
pula.append(p) # dodaj do puli
else:
if len(pula) == 0:
return # zakoncz
else:
break # wroc do petli
sleep(5) # czekaj
if __name__ == '__main__':
run(5)
[/code]
i dostaje po odpaleniu komunikat:
File "tst.py", line 28, in run
if i.is_alive() is False:
AttributeError: 'NoneType' object has no attribute 'is_alive'
Exception in thread QueueFeederThread (most likely raised during
interpreter shutdown):
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 522, in
__bootstrap_inner
File "/usr/lib/python2.6/threading.py", line 477, in run
File "/usr/lib/python2.6/multiprocessing/queues.py", line 233, in
_feed
<type 'exceptions.TypeError'>: 'NoneType' object is not callable
wiec tutaj sie blokuje i nie wiem jak sprawdzic czy dany process jesce
dziala czy nie,
pozdrawiam
p.s.
Technical Details
Message-ID:
<4d45db34-b9c3-4939-8a81-6e6afe9b507c@f35g2000yqd.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!lublin.pl!uw.edu.pl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeder.news-service.com!postnews.google.com!f35g2000yqd.googlegroups.com!not-for-mailReferences:
<77c00642-1b59-418a-a26a-fb99b3c32e81@g11g2000yqe.googlegroups.com> <b630f510-d64c-4eaf-8212-0f1b80d11a1f@v25g2000yqk.googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!lublin.pl!uw.edu.pl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeder.news-service.com!postnews.google.com!f35g2000yqd.googlegroups.com!not-for-mail From: Slawomir Piasecki <piasekps@gmail.com> Newsgroups: pl.comp.lang.python Subject: Re: jak sensownie polaczyc watki z rekurencja? Date: Thu, 25 Feb 2010 08:52:46 -0800 (PST) Organization: http://groups.google.com Lines: 67 Message-ID: <4d45db34-b9c3-4939-8a81-6e6afe9b507c@f35g2000yqd.googlegroups.com> References: <77c00642-1b59-418a-a26a-fb99b3c32e81@g11g2000yqe.googlegroups.com> <b630f510-d64c-4eaf-8212-0f1b80d11a1f@v25g2000yqk.googlegroups.com> NNTP-Posting-Host: 155.210.232.112 Mime-Version: 1.0 X-Trace: posting.google.com 1267116766 5217 127.0.0.1 (25 Feb 2010 16:52:46 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 25 Feb 2010 16:52:46 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f35g2000yqd.googlegroups.com; posting-host=155.210.232.112; posting-account=cEvGhgoAAAAO_qlWfa_TJ-aChbR9nvzN User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100216 Fedora/3.5.8-1.fc11 Firefox/3.5.8,gzip(gfe),gzip(gfe) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit