Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(42)

Issue 69870048: Future.set_result is not safe

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 1 month ago by Nikolay Kim
Modified:
9 years, 10 months ago
Reviewers:
GvR, haypo_gmail
Visibility:
Public.

Description

Future.set_result is not safe

Patch Set 1 #

Patch Set 2 : Use helper function #

Total comments: 5
Unified diffs Side-by-side diffs Delta from patch set Stats (+51 lines, -8 lines) Patch
M asyncio/events.py View 1 1 chunk +7 lines, -0 lines 1 comment Download
M asyncio/proactor_events.py View 1 2 chunks +4 lines, -1 line 0 comments Download
M asyncio/queues.py View 1 1 chunk +3 lines, -1 line 0 comments Download
M asyncio/selector_events.py View 1 3 chunks +7 lines, -2 lines 1 comment Download
M asyncio/tasks.py View 1 1 chunk +3 lines, -1 line 0 comments Download
M asyncio/unix_events.py View 1 3 chunks +8 lines, -3 lines 2 comments Download
M tests/test_selector_events.py View 1 chunk +19 lines, -0 lines 1 comment Download

Messages

Total messages: 10
Nikolay Kim
Future.set_result is not safe to use with loop.call_soon() here is test for that issue: @mock.patch('asyncio.base_events.logger') ...
10 years, 1 month ago (2014-03-03 22:03:25 UTC) #1
Nikolay Kim
On 2014/03/03 22:03:25, Nikolay Kim wrote: > Future.set_result is not safe to use with loop.call_soon() ...
10 years, 1 month ago (2014-03-03 22:04:52 UTC) #2
GvR
Hmm... Are you just concerned about the log messages or is the logic of your ...
10 years, 1 month ago (2014-03-03 22:33:01 UTC) #3
GvR
I should add the behavior of set_result is intentional. Are you seeing these spurious log ...
10 years, 1 month ago (2014-03-03 22:34:33 UTC) #4
Nikolay Kim
On 2014/03/03 22:33:01, GvR wrote: > Hmm... Are you just concerned about the log messages ...
10 years, 1 month ago (2014-03-03 22:46:21 UTC) #5
Nikolay Kim
On 2014/03/03 22:34:33, GvR wrote: > I should add the behavior of set_result is intentional. ...
10 years, 1 month ago (2014-03-03 22:49:48 UTC) #6
Nikolay Kim
On 2014/03/03 22:49:48, Nikolay Kim wrote: > On 2014/03/03 22:34:33, GvR wrote: > > I ...
10 years, 1 month ago (2014-03-04 17:40:26 UTC) #7
GvR
A caveat on my suggestions: various tests fail if I do that. I haven't looked ...
10 years, 1 month ago (2014-03-05 19:59:13 UTC) #8
haypo_gmail
The issue fixed by this patch can still reproduced in Tulip and Python 3.4/3.5. I ...
9 years, 10 months ago (2014-06-30 14:10:24 UTC) #9
haypo_gmail
9 years, 10 months ago (2014-06-30 14:15:34 UTC) #10
https://codereview.appspot.com/69870048/diff/20001/asyncio/events.py
File asyncio/events.py (right):

https://codereview.appspot.com/69870048/diff/20001/asyncio/events.py#newcode20
asyncio/events.py:20: pass
Instead of catching InvalidStateError, I would prefer to check for cancelled
state:

def _maybe_set_result(fut, result):
    if fut.cancelled():
        return
    fut.set_result(result)

https://codereview.appspot.com/69870048/diff/20001/tests/test_selector_events.py
File tests/test_selector_events.py (right):

https://codereview.appspot.com/69870048/diff/20001/tests/test_selector_events...
tests/test_selector_events.py:704: fut = asyncio.Future(loop=self.loop)
I don't think that test_selector_events.py is the right place to test the patch.
The test is not reliable, it depends on the exact execution order of each
function.

IMO a test for the private helper function in test_futures.py should be enough.
Or no test at all? :-p
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b