Skip to content

sock_recv not detected a coroutine #73530

Closed

Description

@JeremyBustamante
BPO 29344
Nosy @gvanrossum, @asvetlov, @berkerpeksag, @1st1
Files
  • issue29344.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-12-20.20:38:50.412>
    created_at = <Date 2017-01-22.14:09:45.357>
    labels = ['type-bug', '3.7', 'docs', 'expert-asyncio']
    title = 'sock_recv not detected a coroutine'
    updated_at = <Date 2018-01-22.18:17:06.131>
    user = 'https://bugs.python.org/JeremyBustamante'

    bugs.python.org fields:

    activity = <Date 2018-01-22.18:17:06.131>
    actor = 'yselivanov'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2017-12-20.20:38:50.412>
    closer = 'asvetlov'
    components = ['Documentation', 'asyncio']
    creation = <Date 2017-01-22.14:09:45.357>
    creator = 'Jeremy Bustamante'
    dependencies = []
    files = ['46483']
    hgrepos = []
    issue_num = 29344
    keywords = ['patch']
    message_count = 15.0
    messages = ['286011', '286575', '286677', '286684', '286689', '286704', '286707', '286710', '308808', '310430', '310431', '310434', '310435', '310442', '310445']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'asvetlov', 'docs@python', 'berker.peksag', 'yselivanov', 'Jeremy Bustamante']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29344'
    versions = ['Python 3.7']

    Activity

    1. JeremyBustamante commented on Jan 22, 2017

      JeremyBustamantemannequin
      MannequinAuthor

      Documemtation says sock_recv is a coroutine
      https://docs.python.org/3.6/library/asyncio-eventloop.html#low-level-socket-operations

      But following code says it isnt:

      import asyncio
      loop = asyncio.get_event_loop()
      
      asyncio.iscoroutinefunction(loop.sock_recv)
      False
      
      asyncio.iscoroutine(loop.sock_recv)
      False
    2. added
      type-bug
      on Jan 22, 2017
    3. berkerpeksag commented on Feb 1, 2017

      @berkerpeksag
      Member

      I'm not really familiar with asyncio terminology, but it looks like it returns a future:

          >>> asyncio.isfuture(loop.sock_recv(sock, 1024))
          True

      There is a also a test in test_selector_events:

          f = self.loop.sock_recv(sock, 1024)
          self.assertIsInstance(f, asyncio.Future)
    4. gvanrossum commented on Feb 1, 2017

      @gvanrossum
      Member

      OP is correct. sock_recv(), sock_sendall(), sock_connect(), sock_accept() all are functions that return Futures. The docs are wrong, as are the docstrings in the code.

    5. berkerpeksag commented on Feb 1, 2017

      @berkerpeksag
      Member

      Here's a patch. sock_connect() wrapped by @coroutine in Lib/asyncio/selector_events.py so I left it as-is. Let me know if it still needs to be updated:

          @coroutine
          def sock_connect(self, sock, address):
              """Connect to a remote socket at address.
          This method is a coroutine.
          """
          ...
      
              return (yield from fut)
    6. added
      docs
      on Feb 1, 2017
    7. 1st1 commented on Feb 1, 2017

      @1st1
      Member

      I think the original idea was to document that all methods of the loop are coroutines, so that:

      1. if a user needs a Future object they call ensure_future:
         fut = asyncio.ensure_future(loop.method())
      1. it gives us ability to refactor things. For instance, sock_connect was a method that returned Futures, but at one point of 3.5 we changed it to be coroutine. Because the method was documented as a coroutine, it wasn't strictly a backwards incompatible way.

      In general, I think it would be safer for us to simple make all loop methods coroutines. Or, less radical, just keeping the status quo: document everything as a coroutine.

    8. gvanrossum commented on Feb 1, 2017

      @gvanrossum
      Member

      The word coroutine has a more specific meaning though (and we have iscoroutine*() inspection functions to check for it).

      Maybe we should switch all these to "awaitable"?

      Also note that in proactor_events.py, sock_connect() is *not* a coroutine. In fact I'm not sure what it is -- it calls self._proactor.connect() which appears to return None from the code in windows_events.py. That's presumably a separate bug.

    9. 1st1 commented on Feb 1, 2017

      @1st1
      Member

      Maybe we should switch all these to "awaitable"?

      I like this! Would it be OK to add a new sphinx declaration? So that:

      .. coroutinemethod:: AbstractEventLoop.shutdown_asyncgens()

      would become:

      .. awaitable:: AbstractEventLoop.shutdown_asyncgens()

      ?

      Also note that in proactor_events.py, sock_connect() is *not* a coroutine.

      Yeah, those small incompatibilities are inevitable for asyncio programs/frameworks -- something that returns a Future may occasionally become a coroutine. Your idea to document API methods as "awaitables" seems to be the right way to go.

      In fact I'm not sure what it is -- it calls self._proactor.connect() which appears to return None from the code in windows_events.py. That's presumably a separate bug.

      It looks like it returns the result of "IocpProactor.connect()" call, which returns an _OverlappedFuture instance (I don't really know Windows part of asyncio code, so I might be missing something).

    10. gvanrossum commented on Feb 1, 2017

      @gvanrossum
      Member

      A new Sphinx declaration sounds great to me, but you might want to check
      with some Sphinx or Python-docs expert.

      I somehow misread the code of IocpProactor.connect(), so ignore that part
      -- the point is that it's not always a coroutine.

    11. asvetlov commented on Dec 20, 2017

      @asvetlov
      Contributor

      sock_recv was converted into genuine coroutine in Python 3.7

      Closing the issue.

    12. berkerpeksag commented on Jan 22, 2018

      @berkerpeksag
      Member

      Andrew, shouldn't we fix 3.6 documentation? sock_* methods still documented as coroutines.

    13. 1st1 commented on Jan 22, 2018

      @1st1
      Member

      Andrew, shouldn't we fix 3.6 documentation? sock_* methods still documented as coroutines.

      We only fixed it in 3.7 and the doc was updated. 3.6 stays as is.

    14. berkerpeksag commented on Jan 22, 2018

      @berkerpeksag
      Member

      We only fixed it in 3.7 and the doc was updated. 3.6 stays as is.

      I'm not talking about fixing code in 3.6. In 3.6, sock_* methods still documented as coroutines but they are normal functions:

      3.6 documentation still needs to be fixed. See my patch.

    15. 1st1 commented on Jan 22, 2018

      @1st1
      Member

      Since we made them coroutines in 3.7, I'd prefer to keep the 3.6 documentation as is (so that people don't write code that expects them to be not coroutines in 3.6).

      Please let's keep the current status quo.

    16. berkerpeksag commented on Jan 22, 2018

      @berkerpeksag
      Member

      Well, the current status quo has already confused a user (see msg286011)

      (so that people don't write code that expects them to be not coroutines in 3.6)

      Even if people expect these methods to be coroutines, two functions of the asyncio public API (iscoroutinefunction() and iscoroutine()) disagree with them as described in msg286011.

      In similar scenarios, we've always keep the code as is and clarified the docs in stable releases, then changed the code behave as documented in master.

    17. 1st1 commented on Jan 22, 2018

      @1st1
      Member

      They have been documented as coroutines and were returning futures since Python 3.4. I believe we can keep the status quo especially if only one user complained about it during the last 5 years.

    18. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)docstopic-asynciotype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions