Skip to content

Commit

Permalink
Initial Cygwin support module with just a bit more than bare-minimum
Browse files Browse the repository at this point in the history
functionality.

Many tests are set to skip on Cygwin for now, but can be re-enabled as
more functionality is added back in.

The C extension module is just a stub for now and might end up being
removed altogether, especially if we can add
[PyCygwin](https://pycygwin.readthedocs.io/en/latest/) as a dependency.
  • Loading branch information
Erik M. Bray committed Apr 8, 2019
1 parent a639fbd commit 931fea6
Show file tree
Hide file tree
Showing 16 changed files with 705 additions and 52 deletions.
29 changes: 24 additions & 5 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- NetBSD
- Sun Solaris
- AIX
- Cygwin (experimental)
Works with Python versions from 2.6 to 3.4+.
"""
Expand Down Expand Up @@ -77,6 +78,7 @@

from ._common import AIX
from ._common import BSD
from ._common import CYGWIN
from ._common import FREEBSD # NOQA
from ._common import LINUX
from ._common import MACOS
Expand Down Expand Up @@ -173,6 +175,10 @@
# via sys.modules.
PROCFS_PATH = "/proc"

elif CYGWIN:
PROCFS_PATH = "/proc"
from . import _pscygwin as _psplatform

else: # pragma: no cover
raise NotImplementedError('platform %s is not supported' % sys.platform)

Expand Down Expand Up @@ -201,7 +207,7 @@
"POWER_TIME_UNKNOWN", "POWER_TIME_UNLIMITED",

"BSD", "FREEBSD", "LINUX", "NETBSD", "OPENBSD", "MACOS", "OSX", "POSIX",
"SUNOS", "WINDOWS", "AIX",
"SUNOS", "WINDOWS", "AIX", "CYGWIN",

# classes
"Process", "Popen",
Expand Down Expand Up @@ -357,7 +363,7 @@ def __init__(self, seconds, pid=None, name=None):
if POSIX:
from . import _psposix
_psposix.TimeoutExpired = TimeoutExpired
if LINUX:
if LINUX or CYGWIN:
from . import _pslinux_common
_pslinux_common.NoSuchProcess = NoSuchProcess
_pslinux_common.ZombieProcess = ZombieProcess
Expand Down Expand Up @@ -662,11 +668,16 @@ def parent(self):
if self.pid == lowest_pid:
return None
ppid = self.ppid()
if CYGWIN:
# See note for Process.create_time in _pscygwin.py
rounding_error = 1
else:
rounding_error = 0
if ppid is not None:
ctime = self.create_time()
try:
parent = Process(ppid)
if parent.create_time() <= ctime:
if parent.create_time() <= (ctime + rounding_error):
return parent
# ...else ppid has been reused by another process
except NoSuchProcess:
Expand Down Expand Up @@ -1495,7 +1506,15 @@ def pids():
"""Return a list of current running PIDs."""
global _LOWEST_PID
ret = sorted(_psplatform.pids())
_LOWEST_PID = ret[0]

if CYGWIN:
# Note: The _LOWEST_PID concept is not very meaningful since every
# "top-level" process has a non-1 PID; they do have PPID of 1 but that
# does not correspend to an actual process that shows up in the pids()
# list
_LOWEST_PID = 1
else:
_LOWEST_PID = ret[0]
return ret


Expand Down Expand Up @@ -2467,7 +2486,7 @@ def test(): # pragma: no cover
else:
cputime = ''

user = p.info['username']
user = p.info['username'] or ''
if not user and POSIX:
try:
user = p.uids()[0]
Expand Down
3 changes: 2 additions & 1 deletion psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
__all__ = [
# constants
'FREEBSD', 'BSD', 'LINUX', 'NETBSD', 'OPENBSD', 'MACOS', 'OSX', 'POSIX',
'SUNOS', 'WINDOWS',
'SUNOS', 'WINDOWS', 'CYGWIN',
'ENCODING', 'ENCODING_ERRS', 'AF_INET6',
# connection constants
'CONN_CLOSE', 'CONN_CLOSE_WAIT', 'CONN_CLOSING', 'CONN_ESTABLISHED',
Expand Down Expand Up @@ -86,6 +86,7 @@
BSD = FREEBSD or OPENBSD or NETBSD
SUNOS = sys.platform.startswith(("sunos", "solaris"))
AIX = sys.platform.startswith("aix")
CYGWIN = sys.platform.startswith("cygwin")


# ===================================================================
Expand Down
Loading

0 comments on commit 931fea6

Please sign in to comment.