This is my first attempt at a C implementation:
https://gist.github.com/doodspav/5d96c09696fa3ef1c89b4d6426ddc338
It stores the `fd` as an atomic int, since I think threads not being able to
run in parallel is an implementation detail, and I shouldn't be designing code
around it? I'm not sure if all Python platforms have a C compiler that supports
stdatomic, but I'll cross that bridge when I get to it.
Right now `read`/`write` raise `BlockingIOError` if the `fd` is set to
non-blocking, and the operation would block - I was considering adding kwargs
to both operations to give the option to return `None`/`False`, but kwargs in C
are annoying, so maybe at a later stage.
To build:
- you'll probably need a lib like `libpython3-dev`
- save the gist into a file called `py_eventfd.c`
- create a file called `setup.py` and paste the following into it:
```py
from distutils.core import setup, Extension
setup(name="eventfd", version="1.0", ext_modules=[Extension("eventfd",
["py_eventfd.c"])])
```
- run `python3 setup.py build` and `cd b*/l*`
- from there you can `import eventfd` or `from eventfd import eventfd`
It should go without saying that this will only compile on Linux.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/EUTBN5F4Q4SH33TAD7CKRKEAAIREY4B4/
Code of Conduct: http://python.org/psf/codeofconduct/