Title: Symmetrical chaining futures in asyncio.future.wrap_future
Type: enhancement Stage: resolved
Components: asyncio Versions: Python 3.8
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, huji, yselivanov
Priority: normal Keywords: patch

Created on 2018-08-18 11:02 by huji, last changed 2019-04-03 08:45 by huji. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8807 open huji, 2018-08-18 14:44
Messages (6)
msg323703 - (view) Author: Alfred Sawaya (huji) * Date: 2018-08-18 11:02
asyncio.future.wrap_future is used to wrap a concurrent.future.Future in a asyncio.future.Future. 

The actual implementation as the following behaviours : 

 1) When the concurrent.future.Future gets a result, the asyncio.future.Future gets the same result,
 2) When the asyncio.future.Future is cancelled, the concurrent.future.Future is cancelled

I wonder why the futures synchronisation is not symmetrical ?
I propose to add the following behaviours : 

 3) When the asyncio.future.Future gets a result, the concurrent.future.Future gets the same result,
 4) When the concurrent.future.Future is cancelled, the asyncio.future.Future is cancelled

I have also posted a request pull that implements the proposed behaviours, in case of acceptation.

If there is good reasons to not implement the proposed behaviours, I would be glad to know.

Thank you !
msg323706 - (view) Author: Alfred Sawaya (huji) * Date: 2018-08-18 11:26
Actually the PR does not pass some tests, I will work on this. If the new behaviours are accepted, I will implement them soon.
msg323715 - (view) Author: Alfred Sawaya (huji) * Date: 2018-08-18 15:28
The proposed solution (PR) has passed all tests.
msg326810 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-10-01 16:06
The PR needs a very careful review, but in general I'm OK with the idea.  I'm also curious why do you want to fix wrap_future -- how are you using it?
msg326868 - (view) Author: Alfred Sawaya (huji) * Date: 2018-10-02 08:41
I use it to integrate a concurrent-based software (B) with an asyncio-based software (A).
(B) will undergo a massive refactoring to become asyncio-based in the future, but for now, I need to use it as-is.
I don't want to modify (A) to handle concurrent.futures.Future (it is developped by another team by the way) and I prefer to begin to implement asyncio into (B).

So (A) waits for a task request with an asyncio.Future, then processes it and populates the Future's result.
(B) has a waiting loop into a thread that handles multiples concurrent.futures.Future.

When (B) receives a request it creates a concurrent.futures.Future and push it into a queue for the waiting loop. If the request asks for a task implemented by (A), it wraps it into an asyncio.Future and call (A) with it.
(A) processes the task and populates the asyncio.Future's result. That's why I needed to implement the proposed behaviours.

Actually I will not need it for long, as (B) will become asyncio-based, but I wanted to integrate (A) and (B) with as less effort as possible, so I implemented my custom Future wrapper, but I think it is useful to refactor concurrent-based software to asyncio incrementally (and I will have to do it multiple times in the near future).
msg339384 - (view) Author: Alfred Sawaya (huji) * Date: 2019-04-03 08:45
Can be closed if not needed by the community.
Date User Action Args
2019-04-03 08:45:32hujisetstatus: open -> closed
resolution: wont fix
messages: + msg339384

stage: patch review -> resolved
2018-10-02 08:41:46hujisetmessages: + msg326868
2018-10-01 16:06:07yselivanovsetmessages: + msg326810
2018-08-18 15:36:17hujisettitle: Double chaining futures in asyncio.future.wrap_future -> Symmetrical chaining futures in asyncio.future.wrap_future
2018-08-18 15:28:56hujisetpull_requests: - pull_request8283
2018-08-18 15:28:42hujisetversions: - Python 3.6, Python 3.7
2018-08-18 15:28:25hujisetmessages: + msg323715
2018-08-18 14:44:15hujisetpull_requests: + pull_request8284
2018-08-18 14:36:05hujisetpull_requests: + pull_request8283
2018-08-18 11:26:58hujisetmessages: + msg323706
2018-08-18 11:25:18hujisetpull_requests: - pull_request8281
2018-08-18 11:18:13hujisetkeywords: + patch
stage: patch review
pull_requests: + pull_request8281
2018-08-18 11:16:03hujisetpull_requests: - pull_request8280
2018-08-18 11:02:20hujicreate