pybind / pybind/pybind11

[FEAT] def_async

Open
#2,658 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

i made a simple Awaitable class in c++ to support pythons async/await syntax with c++ deferred functions:

template<typename ResultType>
class Awaitable : public std::enable_shared_from_this<Awaitable<ResultType>>{
    public:
        Awaitable();
        Awaitable(std::future<ResultType>&);
        std::shared_ptr<Awaitable<ResultType>> __iter__();
        std::shared_ptr<Awaitable<ResultType>> __await__();
        
        void __next__();

    private:
        std::future<ResultType> future;
};

is this something that would have a chance to land in pybind11?
So, supporting an interface like:

m.def_async("name", &function_returning_a_future);

What seems to be missing for this is a StopIteration exception type with templated "return" type.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The proposal centers on a C++ Awaitable class and a hypothetical m.def_async("name", &function_returning_a_future) entry point. Start by determining whether this interface belongs in pybind11 and how the proposed await/next behavior and templated StopIteration return should be scoped; done requires an agreed design and implementation plan.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
18/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.