Path: csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject: + ': 0.07; '"run': 0.09; 'blocking': 0.09; 'expected.': 0.09; 'def': 0.10; 'import': 0.21; 'parse': 0.22; 'help.': 0.22; 'runs': 0.22; 'skip:[ 10': 0.26; 'tree': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'noticed': 0.28; 'run': 0.28; 'normally': 0.30; 'code': 0.31; 'running': 0.32; 'to:addr:python- list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'problem,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'skip:u 20': 0.36; 'two': 0.37; 'why': 0.37; 'received:209': 0.37; 'to:addr:python.org': 0.39; 'here': 0.65; 'running!': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=yndm72461qGUqibuxKec/MY0k2cAKHANol64mIrMMlQ=; b=kuAsovoea6sAvDq35Zrq8ANzU/Yi8EnMbfUguSc17M70vzxIjOg/hkmBLYMeJb8c1D DpyJjEom54ITpmPbgeRfFgn0TEFomdr+QcF9y8Hlpkb1CIrGEQN5oKqT94g/Oh5Id2z+ c19PZEfvJS+6asfMvqTYN6eO2zFQ69KnjqWYF+v0OjL1Sgcmn9D5hYYThYWX3C32G9nM HbtsdRv1CWDwAm2Lykg4MbMKHLKkqZqbf4cU5A1XCnuRkkg9/MSHDrkHQW5z39x9TCYx U6C+lGiwbxjwV9XGJAVrgaDPN29e1yEYvl99HgIMgTJcBXKtKUFgNCBUD9fILtMx/WKW HrrQ== MIME-Version: 1.0 X-Received: by 10.180.103.65 with SMTP id fu1mr4296591wib.4.1361547624462; Fri, 22 Feb 2013 07:40:24 -0800 (PST) Date: Fri, 22 Feb 2013 23:40:24 +0800 Subject: gevent + urllib2 blocking From: =?UTF-8?B?5pyI5b+n6IyX?= To: python-list@python.org Content-Type: multipart/alternative; boundary=f46d044401ca80385504d652028a X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 73 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361547632 news.xs4all.nl 6974 [2001:888:2000:d::a6]:52005 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39582 --f46d044401ca80385504d652028a Content-Type: text/plain; charset=UTF-8 Hi, One problem, thanks for help. import gevent.monkey gevent.monkey.match_all() from lxml import etree # I using xpath parse the html def _get(p): url = BUILD_URL(p) html = urllib2.urlopen(url) # RUN AT HERE AND BLOCKING # ver1 tree = etree.parse(html, parse) # ver2 # tree = etree.fromstring(html.read(), parse) .... workers = [gevent.spawn(_get, i) for i in xrange(1, 100)] gevent.joinall(workers) When using ver1, etree.parse(html, parse) I noticed there are only two greenlets runs at "RUN AT HERE AND BLOCKING" others are not running! But, when I using ver2, this code will running normally as expected. Why this ? --f46d044401ca80385504d652028a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

One problem, thanks for help.


import gevent.monkey
gevent.monkey.match_all= ()

from lxml import etree
# I using xpath parse the html


def= _get(p):
=C2=A0=C2=A0=C2=A0 url =3D BUILD_URL(p)
=C2=A0=C2=A0=C2=A0 = html =3D urllib2.urlopen(url)

=C2=A0=C2=A0=C2=A0 # RUN AT HERE AND B= LOCKING

=C2=A0=C2=A0=C2=A0 # ver1
=C2=A0=C2=A0=C2=A0 tree =3D etr= ee.parse(html, parse)

=C2=A0=C2=A0=C2=A0 # ver2
=C2=A0=C2=A0=C2=A0 # tree =3D etree.fromst= ring(html.read(), parse)

=C2=A0=C2=A0=C2=A0 ....


workers= =C2=A0 =3D [gevent.spawn(_get, i) for i in xrange(1, 100)]
gevent.joinal= l(workers)




When using ver1,=C2=A0 etree= .parse(html, parse)
I noticed there are only two greenlets runs at "RUN AT HERE AND BLOCKI= NG"

others are not running!


But, when I using ver2,= =C2=A0 this code will running normally as expected.


Why this ? <= /div> --f46d044401ca80385504d652028a--