asynchronizer is a simple bridge for synchronization between Boost.Asio and Python 3 asyncio. It provides small Python extension (using pybind11) and Python wrapper.
- You write complex application with asynchronous C++ code and want to use some Python to simplify this challenge.
- You have awesome C++ library using Boost.Asio and want create Python bindings for it.
MIT license. See license.txt.
- Compiler with C++14 support. For example, try
g++
of versions 5/6/... or modernclang
. - Boost (or just Boost.Asio and Boost.System) (
>= 1.66.0
because of Boost.Asio refactoring since1.65
)- Tested: Boost 1.68.0 on Mac OS X 10.11
- Boost.Build (or any other build system -- it's simple).
- Note: Set environment variable
BOOST_ROOT
to unpacked Boost directory path.
- Note: Set environment variable
- Python
>=3.6
- Tested: Python 3.6.4 on Mac OS X 10.11
- Some Python packages (usually installed by pip; see
Installation
section and files: requirements.txt, testing-requirements.txt).
Note: Using Python venv
is recommended.
- Install Python dependencies:
pip install -r requirements.txt
Note: Install dependencies for testing, if you want run tests:
pip install -r testing-requirements.txt
- Build Python extension and stub:
b2
- Install
asynchronizer.py
, Python extension and stub for it into currentsite-packages
directory:
b2 install
- Run some tests, if you want:
b2 install-test-async-sleep-ext
PYTHONPATH="$( pwd )/build/ext:$PYTHONPATH" pytest
Just write your modules using pybind11 as usual!
Wrap your asynchronous code like ext_src/test_async_sleep_ext.cpp does.
Note: asynchronizer
(with some pybind11 magic) provides bindings for some Boost.Asio, so it's enough to import IoContext
and other from installed asynchronizer
module in your Python code: you are not required to copy IoContext
wrapper bindings into your project.
Optional: If your code require std::shared_ptr
-managed classes, you can:
- use directory
include
in header search path in your project - do this in your project:
#include <dkuk/asynchronizer/asynchronizer.hpp> PYBIND11_MODULE(my_module, module) { ... dkuk::asynchronizer::shared_ptr_managed_class<my_class>{module, "MyClass"}; ... }
See tests.
Author: Dmitry Kukovinets, d1021976@gmail.com, 16.03.2019 10:18