Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3a.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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'package,': 0.03; 'handler': 0.05; '(so': 0.07; '*not*': 0.07; 'method.': 0.07; 'default.': 0.09; 'defines': 0.09; 'exceeds': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sure,': 0.09; 'wrote': 0.14; 'thread': 0.14; "(i'm": 0.16; 'blocking': 0.16; 'chris,': 0.16; 'handled.': 0.16; 'handler,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'thread,': 0.16; 'threads,': 0.16; 'threads.': 0.16; 'timeout': 0.16; 'library': 0.18; 'seems': 0.21; 'case.': 0.24; 'stick': 0.24; 'header:X-Complaints-To:1': 0.27; 'quickly': 0.29; 'returned': 0.30; 'asked': 0.31; 'requests': 0.31; "skip:' 10": 0.31; 'block,': 0.31; 'enabled': 0.31; 'libraries': 0.31; 'provided,': 0.31; 'yes.': 0.31; 'handled': 0.32; 'url:python': 0.33; 'candidate': 0.34; 'moment': 0.34; 'received:co.za': 0.34; 'received:za': 0.34; 'but': 0.35; "didn't": 0.36; 'thanks': 0.36; 'url:org': 0.36; 'being': 0.38; 'server': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'does': 0.39; 'bad': 0.39; "couldn't": 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'ensure': 0.60; 'skip:u 10': 0.60; 'read': 0.60; 'most': 0.60; 'new': 0.61; 'url:3': 0.61; 'entire': 0.61; 'back': 0.62; 'times': 0.62; 'guarantee': 0.63; 'skip:n 10': 0.64; 'within': 0.65; 'worth': 0.66; 'benefit': 0.68; 'brain': 0.68; 'difficulty': 0.68; 'frank': 0.68; 'default': 0.69; 'url:4': 0.69; 'received:41': 0.70; 'special': 0.74; 'skip:n 40': 0.81; 'distinguish': 0.84; 'support:': 0.84; 'whereas': 0.91; 'reply,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: threading Date: Wed, 9 Apr 2014 16:46:50 +0200 References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> <87lhveobeq.fsf@elektro.pacujo.net> X-Gmane-NNTP-Posting-Host: 41-133-114-245.dsl.mweb.co.za X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1397054818 news.xs4all.nl 2894 [2001:888:2000:d::a6]:52410 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69957 "Marko Rauhamaa" wrote in message news:87lhveobeq.fsf@elektro.pacujo.net... > "Frank Millman" : > >> I understand that, if one uses threading, each thread *can* block >> without affecting other threads, whereas if one uses the async >> approach, a request handler must *not* block, otherwise it will hold >> up the entire process and not allow other requests to be handled. > > Yes. > >> How does one distinguish betwen 'blocking' and 'non-blocking'? Is it >> either/or, or is it some arbitrary timeout - if a handler returns within >> that time it is non-blocking, but if it exceeds it it is blocking? > > Old-school I/O primitives are blocking by default. Nonblocking I/O is > enabled with the setblocking() method. > > In the new asyncio package, I/O is nonblocking by default (I'm sure, but > didn't verify). > >> In my environment, most requests involve a database lookup. I >> endeavour to ensure that a response is returned quickly (however one >> defines quickly) but I cannot guarantee it if the database server is >> under stress. Is this a good candidate for async, or not? > > Database libraries are notoriously bad for nonblocking I/O. It's nothing > fundamental; it's only that the library writers couldn't appreciate the > worth of async communication. For that, asyncio provides special > support: > > handle-blocking-functions-correctly> > Thanks for the reply, Marko. I did have a look at the link you provided, but at the moment my brain is 'blocking' on this, so I will need to read it a few times to get back into 'async' mode. As I asked Chris, (so you don't have to respond if he already has), I am finding difficulty in understanding the benefit of going async in my case. If most requests require a blocking handler, it seems that I might as well stick with each request being handled by a thread, independent of all other threads. Frank