Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75198
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!border2.nntp.ams2.giganews.com!backlog4.nntp.ams3.giganews.com!backlog4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <1248283536@qq.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | UNSURE 0.235 |
| X-Spam-Level | ** |
| X-Spam-Evidence | '*H*': 0.60; '*S*': 0.07; 'except:': 0.09; 'try:': 0.09; 'def': 0.12; 'thread': 0.14; 'program?': 0.16; 'skip:` 30': 0.16; 'url:%s': 0.16; 'url:shtml': 0.16; 'finished': 0.19; 'skip:p 40': 0.19; 'import': 0.22; 'skip:` 20': 0.24; 'subject:problem': 0.24; 'skip:_ 20': 0.27; 'skip:p 30': 0.29; 'requests': 0.31; "skip:' 10": 0.31; 'ok.': 0.31; 'class': 0.32; 'skip:t 40': 0.33; 'to:name:python-list': 0.33; 'to:addr:python-list': 0.38; 'delete': 0.39; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'name:': 0.61; 'from:charset:utf-8': 0.61; 'skip:n 10': 0.64; 'content-type:application/octet-stream': 0.65; 'virus:src="cid:': 0.66; 'content-type:multipart/related': 0.67; ',the': 0.84; 'filename:fname piece:PNG': 0.84; 'from:addr:1248283536': 0.84; 'from:addr:qq.com': 0.84; 'message-id:@qq.com': 0.84; 'received:qq.com': 0.84; 'x-mailer:qqmail 2.x': 0.84; '\xe2\x80\x8d': 0.84; 'received:183': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201307; t=1406275276; bh=eYIj6rvWc/J6IVB8uphWw0NX8Yg3qVjte4hORinM6nk=; h=X-QQ-FEAT:X-QQ-SSF:X-HAS-ATTACH:X-QQ-BUSINESS-ORIGIN: X-Originating-IP:X-QQ-STYLE:X-QQ-mid:From:To:Subject:Mime-Version:Content-Type:Content-Transfer-Encoding:Date: X-Priority:Message-ID:X-QQ-MIME:X-Mailer:X-QQ-Mailer: X-QQ-SENDSIZE; b=qmza31KNHtICkAI98ubkxjiRp0kLdV8J4kbQpWsFcy5oGpUpw8rnbo0RkCXMlwTgf /MFNqr7nzlumP+q4zwJa7eju5zRKUlgRbyGHI9pBLWjmEDtrX227jtvo1RVnIcMckq HFtmPDA/RRDX5sMmyPN1jhnL6Kdym0F//rXCVgmY= |
| X-QQ-FEAT | GNKBxKwJj+MM6AfCq4qXo/waa8VcH//GDhfF7CykKc3JGdVD9xy+6kB6oNYvl esb7nle8OMNvkQZcLtipf4IdCaQ6K91bV/G9v1RJ8QTZJiRzxB4VqJB57dJWvY72uv33kfA UKR4kmzswR6U8j3eF8YOeDfgZOpvTE7RjOi2c+ft29kBf3ONIA== |
| X-QQ-SSF | 0000000A000000F000000000000000D |
| X-HAS-ATTACH | no |
| X-QQ-BUSINESS-ORIGIN | 2 |
| X-Originating-IP | 221.182.18.2 |
| X-QQ-STYLE | |
| X-QQ-mid | webmail603t1406274324t1827770 |
| From | "水静流深" <1248283536@qq.com> |
| To | "python-list" <python-list@python.org> |
| Subject | problem on multi-threading |
| Mime-Version | 1.0 |
| Content-Type | multipart/related; type="multipart/alternative"; boundary="----=_NextPart_53D20B14_08D36390_71A72F51" |
| Content-Transfer-Encoding | 8Bit |
| Date | Fri, 25 Jul 2014 15:45:24 +0800 |
| X-Priority | 3 |
| X-QQ-MIME | TCMime 1.0 by Tencent |
| X-Mailer | QQMail 2.x |
| X-QQ-Mailer | QQMail 2.x |
| X-QQ-SENDSIZE | 520 |
| X-Mailman-Approved-At | Fri, 25 Jul 2014 10:04:53 +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.12313.1406275494.18130.python-list@python.org> (permalink) |
| Lines | 627 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1406275494 news.xs4all.nl 2954 [2001:888:2000:d::a6]:40375 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Original-Bytes | 48564 |
| Xref | csiph.com comp.lang.python:75198 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
The right program is as following,everything is ok.
import requests
import threading
import queue
class webdata(object):
def __init__(self,name):
self.jobs=queue.Queue()
for x in name:
url='http://stockhtm.finance.qq.com/sstock/ggcx/%s.shtml' %x
self.jobs.put(url)
def download(self):
while not self.jobs.empty():
try:
url = self.jobs.get()
print(requests.get(url).status_code,url)
print(threading.currentThread())
self.jobs.task_done()
except:
print("wrong",url)
self.jobs.task_done()
def run(self):
for i in range(3):
threading.Thread(target=self.download).start()
self.jobs.join()
print("i am over")
name=['600000', '000001', '600319', '600531','600661', '600983', '600202', '600149']
x=webdata(name)
x.run()
question1:
when i delete the line of `self.jobs.join()` ,the program will never finished ,why?
import requests
import threading
import queue
class webdata(object):
def __init__(self,name):
self.jobs=queue.Queue()
for x in name:
url='http://stockhtm.finance.qq.com/sstock/ggcx/%s.shtml' %x
self.jobs.put(url)
def download(self):
while not self.jobs.empty():
try:
url = self.jobs.get()
print(requests.get(url).status_code,url)
print(threading.currentThread())
self.jobs.task_done()
except:
print("wrong",url)
self.jobs.task_done()
def run(self):
for i in range(3):
threading.Thread(target=self.download).start()
self.jobs.join()
print("i am over")
name=['600000', '000001', '600319', '600531','600661', '600983', '600202', '600149']
x=webdata(name)
x.run()
never quit from the thread ,why?
question2:
I can get every son-thread thread number with `print(threading.currentThread()) `,how can i get the main thread number in the program?
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
problem on multi-threading "水静流深" <1248283536@qq.com> - 2014-07-25 15:45 +0800
csiph-web