Skip to main content

Different operating systems provide different ways to wait for I/O completion events: there’s select(), poll(), epoll() and kqueue(). For cross-platform applications it can be a pain to support all this system functions, especially because each one provides a different interface.

IOWait solves this problem by providing a unified interface and using always the best and faster function available in the platform. Its only limitation is that, on Windows, it only works for sockets.

This library is compatible both with Python 2 and 3.

Example

Here is an usage example. First, we need to create a pair of sockets:

>>> import socket
>>> a, b = socket.socketpair()

Then we create a IOWait object. This object is essentially a wrapper around a system function (such as select() or poll()), but exposes always the same methods and behaves always the same.

>>> from iowait import IOWait
>>> waitobj = IOWait()

Now we can watch the first socket for read events in this way:

>>> waitobj.watch(a, read=True)

We send some data over the other socket:

>>> b.sendall('this is a test')

Calling wait() on the IOWait object will tell us that the socket a is ready to be read:

>>> events = waitobj.wait()
>>> events #doctest:+ELLIPSIS
[IOEvent(fileobj=<socket object, ...>, read=True, write=False)]

The return value of wait() is a list of three-tuples in the format: (file, read, write), where file is a file-like object, read and write tell respectively whether the file is ready to be read or written.

Once all the data has been read, the next call to wait() will block forever, unless a timeout is specified. The timeout can be zero:

>>> a.recv(14)
'this is a test'
>>> waitobj.wait(0)
[]

Documentation

The documentation is stored in the module’s doc string. To read it, use the Python interactive interpreter:

>>> import iowait
>>> help(iowait) #doctest:+SKIP

Metadata

Release files for iowait 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iowait 0.2
File Size Uploaded
iowait-0.2.tar.gz 22.3 kB Details

Release files / iowait-0.2.tar.gz

Download URL iowait-0.2.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ab1bc2eb84c22ccf61f17a0024f9fb6df781b39f1852764a66a7769d5adfb299
BLAKE2b-256 checksum
How to use checksums
6530e953673fe9619938e9c74408401cf865f37716da89f61f6e5d9328c0f71e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page