Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #55484
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <luolee.me@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'output': 0.05; '"""': 0.07; '-*-': 0.07; 'debug': 0.07; 'utf-8': 0.07; 'coding:': 0.09; 'line:': 0.09; 'processing,': 0.09; 'subject:Why': 0.09; 'try:': 0.09; 'python': 0.11; 'def': 0.12; 'thread': 0.14; 'empty,': 0.16; 'empty.': 0.16; 'inputs': 0.16; 'outputs': 0.16; 'subject:threads': 0.16; 'true:': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'input': 0.22; 'example': 0.22; 'import': 0.22; 'putting': 0.22; 'print': 0.22; 'skip:l 30': 0.24; "i've": 0.25; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'that.': 0.31; 'class': 0.32; 'another': 0.32; 'url:python': 0.33; 'fri,': 0.33; 'skip:# 10': 0.33; 'skip:_ 10': 0.34; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'doing': 0.36; "didn't": 0.36; 'thanks': 0.36; 'url:org': 0.36; 'list': 0.37; 'implement': 0.38; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'break': 0.61; 'skip:t 30': 0.61; 'from:charset:utf-8': 0.61; "you're": 0.61; 'hang': 0.67; 'url:me': 0.69; 'is!': 0.84; 'died': 0.91; 'here."': 0.91; 'whereas': 0.91; 'reply,': 0.93; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=u2MgB0OccgJvUY6AbMO5sdUmsh/ysLp1byIiGALlS2M=; b=TZBouVqFPT22s+yhtXE5CvaI7U7XAmjtruaf+hlv24+nikq9SpppC7nijMkoiA21/7 OJYpIvJmBLO/s70//gZCuTo6rjwA6a6rymvU3r6RbJphqDtYywIlYpR7BXieoUkAtuvC 9g4lADBIsq79LFqaatxT6XIWNUeGffCc2bZ1yv1VWK9cwCWzNrqjQj97T1hqb8oxfOZa X3/l36YHuGs9XNIfFRv1qNQ5WBlJPMKdX91HmMSRc/Mc/fZ2HR0omBQm4KZUqIWTRAy7 sOWUSiz8IbZnEb24aEiRNfIAdKuit8dwOHqp6PTtmgOJo//JG4j9uvAINHDM0d4UN2oq Cq6Q== |
| MIME-Version | 1.0 |
| X-Received | by 10.194.23.73 with SMTP id k9mr13706333wjf.24.1380904873554; Fri, 04 Oct 2013 09:41:13 -0700 (PDT) |
| In-Reply-To | <524DB6AA.4080704@mrabarnett.plus.com> |
| References | <CACb3DvNqwT3O1tOnr1eCobCxp4R8ZxuEJCUDO4j=9VQfZpQrUQ@mail.gmail.com> <524DB6AA.4080704@mrabarnett.plus.com> |
| Date | Sat, 5 Oct 2013 00:41:13 +0800 |
| Subject | Re: Why didn't my threads exit correctly ? |
| From | 李洛 <luolee.me@gmail.com> |
| To | python-list@python.org |
| Content-Type | multipart/alternative; boundary=047d7b5d439674f88804e7ecf86c |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.725.1380904880.18130.python-list@python.org> (permalink) |
| Lines | 194 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1380904880 news.xs4all.nl 15916 [2001:888:2000:d::a6]:51251 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:55484 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Thanks for your reply, MRAB.
I've seen that the child thread has been stoped, it just died in the
queue.If I want the queue be empty, I must use queue.get() to dequeue and
clean it, but I didn't do that.
I've implement the thread using List now, thanks again.
On Fri, Oct 4, 2013 at 2:25 AM, MRAB <python@mrabarnett.plus.com> wrote:
> On 03/10/2013 18:37, 李洛 wrote:
>
>> Hi list,
>> I write an example script using threading as follow.
>> It look like hang when the list l_ip is empty. And any suggestion with
>> debug over the threading in Python ?
>>
>> 1 #!/usr/bin/env python
>> 2 # -*- coding: utf-8 -*-
>> 3 import re
>> 4 import os
>> 5 import threading
>> 6 from Queue import Queue
>> 7 from time import sleep
>> 8
>> 9 l_ip = []
>> 10 l_result = []
>> 11 result = re.compile(r"[1-3] received")
>> 12
>> 13 class ping(threading.Thread):
>> 14 """ """
>> 15 def __init__(self, l_ip, l_result):
>> 16 threading.Thread.__init__(**self)
>> 17 self.l_ip = l_ip
>> 18 #self.l_result = l_result
>> 19
>> 20 def run(self):
>> 21 """ """
>> 22 while True:
>> 23 try:
>> 24 ip = self.l_ip.pop()
>> 25 except IndexError as e:
>> 26 print e
>> 27 break
>> 28 ping_out = os.popen(''.join(['ping -q -c3 ',ip]), 'r')
>> 29 print 'Ping ip:%s' % ip
>> 30 while True:
>> 31 line = ping_out.readline()
>> 32 if not line: break
>> 33 if result.findall(line):
>> 34 l_result.append(ip)
>> 35 break
>> 36
>> 37 queue = Queue()
>> 38
>> 39 for i in range(1,110):
>> 40 l_ip.append(''.join(['192.168.**1.', str(i)]))
>> 41 for i in xrange(10):
>> 42 t = ping(l_ip, l_result)
>> 43 t.start()
>> 44 queue.put(t)
>> 45 queue.join()
>> 46 print "Result will go here."
>> 47 for i in l_result:
>> 48 print 'IP %s is OK' % i
>>
>> queue.join() will block until the queue is empty, which is never is!
>
> You're putting the workers in the queue, whereas the normal way of
> doing it is to put them into a list, the inputs into a queue, and the
> outputs into another queue. The workers then 'get' from the input
> queue, do some processing, and 'put' to the output queue.
>
> --
> https://mail.python.org/**mailman/listinfo/python-list<https://mail.python.org/mailman/listinfo/python-list>
>
--
All the best!
http://luolee.me
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Why didn't my threads exit correctly ? 李洛 <luolee.me@gmail.com> - 2013-10-05 00:41 +0800 Re: Why didn't my threads exit correctly ? Piet van Oostrum <piet@vanoostrum.org> - 2013-10-05 15:22 -0400
csiph-web