Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'handler': 0.05; 'newbie': 0.05; '*not*': 0.07; 'lesser': 0.07; 'processing.': 0.07; 'defines': 0.09; 'exceeds': 0.09; 'here?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; 'thread': 0.14; 'event- driven': 0.16; 'handled.': 0.16; 'handler,': 0.16; 'language)': 0.16; 'losing': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'threads,': 0.16; 'timeout': 0.16; 'question': 0.24; 'right.': 0.26; 'header:X-Complaints- To:1': 0.27; 'quickly': 0.29; 'returned': 0.30; 'requests': 0.31; "skip:' 10": 0.31; 'block,': 0.31; 'closer': 0.31; 'candidate': 0.34; 'received:co.za': 0.34; 'received:za': 0.34; 'but': 0.35; 'thanks': 0.36; 'too': 0.37; 'server': 0.38; 'machines': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'ensure': 0.60; 'worry': 0.60; 'most': 0.60; 'entire': 0.61; 'guarantee': 0.63; 'skip:n 10': 0.64; 'taking': 0.65; 'within': 0.65; 'frank': 0.68; 'results': 0.69; 'received:41': 0.70; 'led': 0.72; 'skip:n 40': 0.81; 'asynchronous': 0.84; 'complex,': 0.84; 'distinguish': 0.84; 'interrupt': 0.84; 'polling': 0.84; 'whereas': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: threading Date: Wed, 9 Apr 2014 15:23:33 +0200 References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1397049831 news.xs4all.nl 2939 [2001:888:2000:d::a6]:35834 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69945 "Marko Rauhamaa" wrote in message news:877g70wg8p.fsf@elektro.pacujo.net... > Dennis Lee Bieber : > >> That's been my experience too... Threading works for me... My >> attempts at so called asyncio (whatever language) have always led to >> my having to worry about losing data if some handler takes too long to >> return. >> >> To me, asyncio is closer to a polling interrupt handler, and I >> still need a thread to handle the main processing. > > Yes, asynchronous processing results in complex, event-driven state > machines that can be hard to get right. However, my experience is that > that's the lesser evil. > > About a handler taking too long: you need to guard each state with a > timer. Also, you need then to handle the belated handler after the timer > has expired. > Can I ask a newbie question here? 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. 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? 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? Thanks for any insights. Frank Millman