[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Idea for an event loop library
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 10 May 2012 10:50:03 +0200
On Thu, May 10, 2012 at 10:23 AM, Rob Hoelz <firstname.lastname@example.org> wrote:
> I'll probably expose the low-level coroutine stuff at some level for
> advanced users/users that wish to extend the library.
Coroutines can make event-based programming 'natural' but you do need
to avoid blocking like the plague.
So if a person wishes to actually do some heavy computation, they need
to understand that they must let the system do some work, with a
sleep(0) or something similar. (this is something that early Windows
programmers needed to know, before truly preemptive threading)
Anything that does I/O can block, particularly sockets, but also when
launching a new process. Copas does that nicely for sockets, (but
using timeout tricks), and there has to be a non-blocking equivalent
of popen. in the absence of true threading, that is the best workhorse
for doing time-consuming calculations.
So, if the API is available, and people learn not to just use standard
I/O and os.popen, then things do work smoothly.
The alternative is very nasty-looking, even without error checking: