Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: cross platform alternative for signal.SIGALRM? Date: Thu, 12 Nov 2015 18:37:02 +1100 Lines: 23 Message-ID: References: <877flnu4kn.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de 1S9ADOzu4UnaRemRkcApLQNJ2I0tO1Fu/OpJf34qUGAQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:skip:s 10': 0.05; '(b)': 0.07; 'correct.': 0.07; 'socket': 0.07; 'cc:addr:python- list': 0.09; 'abstraction': 0.09; 'loop.': 0.09; 'output': 0.13; 'thu,': 0.15; '"hey': 0.16; 'async': 0.16; 'cleaner': 0.16; 'computes': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'readable': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:alternative': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'creates': 0.18; 'library': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(a)': 0.22; 'code,': 0.23; 'bit': 0.23; 'finished': 0.23; "haven't": 0.24; 'header:In-Reply-To:1': 0.24; 'requests': 0.25; 'sort': 0.25; "i've": 0.25; "doesn't": 0.26; 'room': 0.27; 'message- id:@mail.gmail.com': 0.27; '(it': 0.29; 'long.': 0.29; 'periodic': 0.29; '(c)': 0.29; 'system,': 0.30; 'code': 0.30; 'becomes': 0.30; 'checks': 0.30; 'says': 0.32; 'maybe': 0.33; 'run': 0.33; 'common': 0.33; 'call,': 0.33; 'server': 0.34; 'received:google.com': 0.35; 'nov': 0.35; 'but': 0.36; 'too': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; '12,': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'christian': 0.38; 'someone': 0.38; 'data': 0.39; 'sure': 0.39; 'still': 0.40; 'some': 0.40; 'chance': 0.60; 'waiting': 0.60; 'your': 0.60; 'skip:u 10': 0.61; 'clients': 0.61; 'more': 0.63; 'within': 0.64; '(they': 0.84; 'chrisa': 0.84; 'gollwitzer': 0.84; 'hour,': 0.84; 'ultimately,': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=plaZtx4DscC6SstdUnLc6p8cQr4i7/MBq1OUEbOY21U=; b=IFj2zSzCxP70x2cIfCZkH8kY+WkIOHiVA1Ph6TvDsLAegU3My+EyieYWp9BM5hxgz8 KBUjQZK3xt2gpkwc3CzWDSDzz+TNNzA7hpF4cbtM1UuZz7F+ip/c3M5VaNtzBCUnHPKe PKdOpMWKB2dsMEpEuoKWhFy97bgz0zimJs89lIhyf2kcRhMQ8MfCEC5JIpJuCV7B3pE8 a93rszlWAgKHhZsxMdCeUQNy9bEPrIHy31EymhV9Vp5AWgrFXxKrlPnn6YTrKP3ne3Ca MQubVUFIWHzebfRwe19guWToq9V1H3o8lLtOhOABe7gwkB1DT9iaprIVJbsMH81vyJ6j kxKA== X-Received: by 10.50.132.101 with SMTP id ot5mr13925567igb.13.1447313822421; Wed, 11 Nov 2015 23:37:02 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98678 On Thu, Nov 12, 2015 at 5:43 PM, Christian Gollwitzer wrote: > My understanding of async is that it creates an event loop. In which case > the loop has no chance to run within a block of code that computes anything, > is that correct? This is correct. At its simplest, asynchronous code is an abstraction over the select() call, which basically says "Hey system, tell me when (a) I can read from here, (b) I can write to here, or (c) I've been waiting this long". The most common use is sockets; a web server has its main listening socket (it becomes readable when someone connects), any clients that haven't finished sending their requests yet (they become readable when more data arrives), any clients that you're still sending to (they become writeable when there's room in their output buffers), and maybe some sort of periodic checks ("every hour, do maintenance"). Whenever you finish a bit of processing (reading from a client, sending to a client, whatever), you return to the "event loop", which in this case would be select(). An async library makes all this look a lot cleaner in your code, but ultimately, it's not preemptive. You still have to make sure the processing doesn't take too long. ChrisA