Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: Question about asyncio doc example Date: Thu, 24 Jul 2014 08:54:07 +0300 Organization: A noiseless patient Spider Lines: 18 Message-ID: <87d2cvti80.fsf@elektro.pacujo.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx05.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="22583"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//3JqwuBvDDrgIuG1FT/MH" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:vB4T0VZUwB5WG1Q+T3+E+jEYXlY= sha1:NeevsMU/JEI1UYwbeUL0POcycQA= Xref: csiph.com comp.lang.python:75126 Saimadhav Heblikar : > For situations where I dont really know how long a function is going > to take(say waiting for user input or a network operation), I am > better off using callbacks than "yield from asyncio.sleep()". Is my > understanding correct? If you choose the coroutine style of programming, you wouldn't normally use callbacks. Instead, you would "yield from" any blocking event. There are coroutine equivalents for locking, network I/O, multiplexing etc. The callback style encodes the state in a variable. The coroutine style (which closely resembles multithreading), encodes the state in the code itself. Both styles can easily become really messy (because reality is surprisingly messy). Marko