Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62639

Re: Using asyncio in event-driven network library

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.024
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'yet.': 0.04; 'cc:addr :python-list': 0.11; 'python': 0.11; 'gui': 0.12; '23,': 0.16; 'beautifully': 0.16; 'event-driven': 0.16; 'fits': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'handling,': 0.16; 'it;': 0.16; 'iteration': 0.16; 'subject:library': 0.16; 'wrote:': 0.18; 'library': 0.18; 'module': 0.19; 'trying': 0.19; 'code,': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; '[1]': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'that.': 0.31; 'easy,': 0.31; 'run': 0.32; 'another': 0.32; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doubt': 0.36; 'module.': 0.36; 'doing': 0.36; 'two': 0.37; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'extremely': 0.39; 'sure': 0.39; 'how': 0.40; 'even': 0.60; 'easy': 0.60; 'new': 0.61; 'simple': 0.61; 'first': 0.61; 'kind': 0.63; 'asynchronous': 0.84; 'nice,': 0.84; 'pump': 0.84; 'subject:Using': 0.84; 'to:none': 0.92; '2013': 0.98
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=D4kDls0A8rIQHa+j/gT7tCH7TgQ5YGg7SevfenKTwtE=; b=CAcZ7GumAym4JQiQy037nrVX0C8/2+skdj6GVlI3wce8t+Dycg4WKfkRLMboo7lfxg 1AMYEEiBfAxleUPFhchZKikTpXX/PEhxTvd+sQ8sCdF6sFUTgT9d6CWx/qrxV69lzF3e /XP+TXB6tnLv+PE0zBDc6+wjrqwvegmDT6X+4WdMvaN5O8ZTFMc7WhwXobVneHl29dmg eZ4DaXbXjJGi7T2IvULLBAQmLwmnQLxF5h8ngUY1kbWqgSmuRzyprwDEs2jrL9lBsbgK Pd08zgVQfuPji9XfZhYngeGudnRCIURNvtEHdGrfMjPCIaxk8DuNKgQRsetWCXCqhsWp 7Qow==
MIME-Version 1.0
X-Received by 10.66.102.39 with SMTP id fl7mr26660796pab.43.1387817236752; Mon, 23 Dec 2013 08:47:16 -0800 (PST)
In-Reply-To <52B82385.9080604@tobix.eu>
References <52B82385.9080604@tobix.eu>
Date Tue, 24 Dec 2013 03:47:16 +1100
Subject Re: Using asyncio in event-driven network library
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.4566.1387817241.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387817241 news.xs4all.nl 2849 [2001:888:2000:d::a6]:46377
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62639

Show key headers only | View raw


On Mon, Dec 23, 2013 at 10:50 PM, Tobias M. <tm@tobix.eu> wrote:
> I am currently writing an event-driven client library for a network protocol
> [1] and chose to use the new asyncio module. I have no experience with
> asynchronous IO and don't understand all the concepts in asyncio yet. So I'm
> not sure if asyncio is actually the right choice .

As was acknowledged on -tutor, asyncio is extremely new. I don't know
if anyone's yet used it for GUI handling, or even if the module was
intended for that.

You may be able to wrap your GUI code up so it fits inside asyncio.
Rather than run a simple event loop, you could have your own loop that
does some kind of checking: PyGTK has functions for peeking at events
and doing just one iteration of the main loop, so you could pump all
events with something like this:

while gtk.events_pending(): gtk.main_iteration()

No doubt other toolkits have something similar.

Alternatively, you could run two threads: one for your GUI, and
another one for your asyncio. How easy and clean that would be is hard
to say without trying it; it could work out beautifully for your code,
or it could be horribly clunky.

This might be your big contribution to Python for the year: a nice,
easy, working example of using asyncio with a GUI toolkit! You might
be the first to look for this, but you won't be the last.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Using asyncio in event-driven network library Chris Angelico <rosuav@gmail.com> - 2013-12-24 03:47 +1100

csiph-web