# Buggy code
def select(self, timeout=None):
    if timeout is not None:
        timeout = max(timeout, 0)

    max_events = len(self._fd_to_key) * 2
    ready_fds = {}

    kevent_list = _syscall_wrapper(
        self._kqueue.control, True, None, max_events, timeout
    )

    for kevent in kevent_list:
        fd = kevent.ident
        event_mask = kevent.filter
        events = 0
        if event_mask == select.KQ_FILTER_READ:
            events |= EVENT_READ
        if event_mask == select.KQ_FILTER_WRITE:
            events |= EVENT_WRITE

        key = self._key_from_fd(fd)
        if key:
            if key.fd not in ready_fds:
                ready_fds[key.fd] = (key, events & key.events)
            else:
                old_events = ready_fds[key.fd][1]
                ready_fds[key.fd] = (key, (events | old_events) & key.events)

    return list(ready_fds.values())


# Traceback (TypeError)
The full traceback is:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 138, in run
res = self._execute()
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 561, in _execute
result = self._handler.run(task_vars=variables)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/command.py", line 24, in run
results = merge_hash(results, self._execute_module(task_vars=task_vars, wrap_async=wrap_async))
File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/__init__.py", line 810, in _execute_module
res = self._low_level_execute_command(cmd, sudoable=sudoable, in_data=in_data)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/__init__.py", line 917, in _low_level_execute_command
rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py", line 984, in exec_command
(returncode, stdout, stderr) = self._run(cmd, in_data, sudoable=sudoable)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py", line 258, in wrapped
return_tuple = func(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py", line 878, in _run
return self._bare_run(cmd, in_data, sudoable=sudoable, checkrc=checkrc)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py", line 715, in _bare_run
events = selector.select(timeout)
File "/usr/lib/python2.7/dist-packages/ansible/compat/selectors/_selectors2.py", line 464, in select
maxevents=max_events)
File "/usr/lib/python2.7/dist-packages/ansible/compat/selectors/_selectors2.py", line 139, in _syscall_wrapper
raise OSError(errno=errno.ETIMEDOUT)
TypeError: exceptions.OSError does not take keyword arguments

fatal: [staging.bizlock.net]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}

# Fixed code
def select(self, timeout=None):
    if timeout is not None:
        timeout = max(timeout, 0)

    max_events = len(self._fd_to_key) * 2
    ready_fds = {}

    kevent_list = _syscall_wrapper(
        self._wrap_control, True, None, max_events, timeout=timeout
    )

    for kevent in kevent_list:
        fd = kevent.ident
        event_mask = kevent.filter
        events = 0
        if event_mask == select.KQ_FILTER_READ:
            events |= EVENT_READ
        if event_mask == select.KQ_FILTER_WRITE:
            events |= EVENT_WRITE

        key = self._key_from_fd(fd)
        if key:
            if key.fd not in ready_fds:
                ready_fds[key.fd] = (key, events & key.events)
            else:
                old_events = ready_fds[key.fd][1]
                ready_fds[key.fd] = (key, (events | old_events) & key.events)

    return list(ready_fds.values())