<commit_before>#!/usr/bin/env python

# Copyright (c) 2009, <NAME>'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Routines common to all posix systems."""

import os
import errno
import sys
import time
import glob

from psutil._compat import PY3, unicode
from psutil._error import TimeoutExpired
from psutil._common import nt_diskinfo, usage_percent, memoize


def pid_exists(pid):
    """Check whether pid exists in the current process table."""
    if pid < 0:
        return False
    try:
        os.kill(pid, 0)
    except OSError:
        e = sys.exc_info()[1]
        return e.errno == errno.EPERM
    else:
        return True
<commit_msg>(POSIX / pid_exists()) - as a follow up of http://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid/6940314#comment11929962_6940314 be more explicit in handing os.kill() error codes and raise exception if errcode not in (ESRCH, EPERM)<commit_after>#!/usr/bin/env python

# Copyright (c) 2009, <NAME>'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Routines common to all posix systems."""

import os
import errno
import sys
import time
import glob

from psutil._compat import PY3, unicode
from psutil._error import TimeoutExpired
from psutil._common import nt_diskinfo, usage_percent, memoize


def pid_exists(pid):
    """Check whether pid exists in the current process table."""
    if pid < 0:
        return False
    try:
        os.kill(pid, 0)
    except OSError:
        err = sys.exc_info()[1]
        if err.errno == errno.ESRCH:
            # ESRCH == No such process
            return False
        elif err.errno == errno.EPERM:
            # EPERM clearly means there's a process to deny access to
            return True
        else:
            # According to "man 2 kill" possible error values are
            # (EINVAL, EPERM, ESRCH) therefore we should bever get
            # here. If we do let's be explicit in considering this
            # an error.
            raise err
    else:
        return True

{'fraction_non_alphanumeric': 0.08402203856749312, 'fraction_numerical': 0.02066115702479339, 'mean_word_length': 2.699490662139219, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1830520', 'n_tokens_mistral': 685, 'n_tokens_neox': 628, 'n_words': 253}