Skip to content

socket.setblocking(0) changes socket.type #74390

Closed

Description

@giampaolo
BPO 30204
Nosy @giampaolo, @vadmium
Superseder
  • bpo-21327: socket.type value changes after using settimeout()
  • 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-04-29.09:31:34.033>
    created_at = <Date 2017-04-29.08:23:43.135>
    labels = ['3.7', 'library']
    title = 'socket.setblocking(0) changes socket.type'
    updated_at = <Date 2017-04-29.09:31:34.031>
    user = 'https://github.com/giampaolo'

    bugs.python.org fields:

    activity = <Date 2017-04-29.09:31:34.031>
    actor = 'giampaolo.rodola'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-04-29.09:31:34.033>
    closer = 'giampaolo.rodola'
    components = ['Library (Lib)']
    creation = <Date 2017-04-29.08:23:43.135>
    creator = 'giampaolo.rodola'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30204
    keywords = []
    message_count = 3.0
    messages = ['292576', '292587', '292588']
    nosy_count = 2.0
    nosy_names = ['giampaolo.rodola', 'martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '21327'
    type = None
    url = 'https://bugs.python.org/issue30204'
    versions = ['Python 3.6', 'Python 3.7']

    Activity

    1. giampaolo commented on Apr 29, 2017

      @giampaolo
      ContributorAuthor

      This caused me a lot of headaches (broken test) before figuring out what the heck was wrong: =)

      >>> import socket
      >>> s = socket.socket()
      >>> s.type
      <SocketKind.SOCK_STREAM: 1>
      >>> s.setblocking(0)
      >>> s.type
      2049
      >>> s.setblocking(1) 
      >>> s.type
      <SocketKind.SOCK_STREAM: 1>

      getsockopt() on the other hand always tells the truth:

      >>> s.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
      1

      ...so I suppose we can do that in the "type" property of the Python socket class.
      It appears the type is set in socket init:

      s->sock_type = type;

      ...and it's changed later in setblocking:
      s->sock_type |= SOCK_NONBLOCK;

    2. added
      3.7 (EOL)
      stdlib
      on Apr 29, 2017
    3. vadmium commented on Apr 29, 2017

      @vadmium
      Member

      Is this a duplicate of bpo-21327? There is some discussion there and a patch to add get_socket_type that excludes SOCK_NONBLOCK.

    4. giampaolo commented on Apr 29, 2017

      @giampaolo
      ContributorAuthor

      Woo! I completely forgot I already bumped into this and that I even filed a ticket for it.

    5. 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)stdlib

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions