Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55431

Why didn't my threads exit correctly ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!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.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '"""': 0.07; '-*-': 0.07; 'debug': 0.07; 'utf-8': 0.07; 'coding:': 0.09; 'line:': 0.09; 'subject:Why': 0.09; 'try:': 0.09; 'python': 0.11; 'def': 0.12; 'empty.': 0.16; 'subject:threads': 0.16; 'true:': 0.16; 'subject: ?': 0.16; 'example': 0.22; 'import': 0.22; 'print': 0.22; 'skip:l 30': 0.24; 'script': 0.25; 'message-id:@mail.gmail.com': 0.30; 'class': 0.32; 'skip:# 10': 0.33; 'skip:_ 10': 0.34; 'except': 0.35; 'received:google.com': 0.35; 'list': 0.37; '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; 'break': 0.61; 'skip:t 30': 0.61; 'from:charset:utf-8': 0.61; '8bit%:95': 0.64; 'hang': 0.67; 'url:me': 0.69; '8bit%:94': 0.72; 'here."': 0.91; '8bit%:90': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=u37qFEdqpRxD0jG9k+Dfky+w0mOsYdJ9qDLapuZ7g9E=; b=wvZLmVZuYjlKAHffSH4U1AaX9zn5bfyn2G/FjG8STuKszf8RI4ZCdvyVvQ7oQoRfUU M5kILncJJ4oAuoBIXnzxeoC/CZOC8+JykN+sH/BkZu6cigvBu1qbls+OMUApHCVsiW8i eNpDHQFpPODSpY5cIuqyk58AP9jXqTapLEeI8j+f7iiWWeTgEA/5UDlxZYSrEJn+lMur 2QrxY91LzOqqYT6IyafhJ2FT9bVs4an+o6Q4DkS8coF6+GLZEjWOCVyr9E0N0duX1rdF l+N0YsGr0Rvw+b0yNtdCy098Kq3DkVYSFydv0g0+O7c+osNK5IkaPE8ltDMkD0t4DYau 6H0w==
MIME-Version 1.0
X-Received by 10.194.240.129 with SMTP id wa1mr8276560wjc.31.1380821840329; Thu, 03 Oct 2013 10:37:20 -0700 (PDT)
Date Fri, 4 Oct 2013 01:37:20 +0800
Subject Why didn't my threads exit correctly ?
From 李洛 <luolee.me@gmail.com>
To python-list@python.org
Content-Type multipart/alternative; boundary=089e013d1db24a83c004e7d9a363
X-Mailman-Approved-At Thu, 03 Oct 2013 19:55:39 +0200
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.689.1380822940.18130.python-list@python.org> (permalink)
Lines 109
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1380822940 news.xs4all.nl 16009 [2001:888:2000:d::a6]:44151
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:55431

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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

-- 
All the best!

http://luolee.me

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Why didn't my threads exit correctly ? 李洛 <luolee.me@gmail.com> - 2013-10-04 01:37 +0800

csiph-web