Skip to content

Conversation

simpkins
Copy link
Contributor

@simpkins simpkins commented Feb 5, 2021

Stack from ghstack:

Summary:
Check if we are on Windows using sys.platform rather than
platform.system(). Even though platform.system() is more modern, it
has a few downsides: this performs a runtime check of the platform type,
which has non-zero overhead. On Linux it actually executes the separate
/bin/uname process. On the other hand sys.platform is determined
when the Python interpreter is compiled, so this is a simple hard-coded
string.

Because it is a runtime check, platform.system() checks also cannot be
analyzed by static type checkers like Pyre and Mypy. These type
checkers do understand sys.platform checks, and can correctly avoid
complaining about code paths that use platform-specific modules and
functions. e.g., they can avoid complaining about ctypes.WinDLL not
existing on Linux if its use is guarded by a sys.platform check.

Test Plan:
Ran tests on Linux, and will check CI test results.

Differential Revision: D26271724

Summary:
Check if we are on Windows using `sys.platform` rather than
`platform.system()`.  Even though `platform.system()` is more modern, it
has a few downsides: this performs a runtime check of the platform type,
which has non-zero overhead.  On Linux it actually executes the separate
`/bin/uname` process.  On the other hand `sys.platform` is determined
when the Python interpreter is compiled, so this is a simple hard-coded
string.

Because it is a runtime check, `platform.system()` checks also cannot be
analyzed by static type checkers like Pyre and Mypy.  These type
checkers do understand `sys.platform` checks, and can correctly avoid
complaining about code paths that use platform-specific modules and
functions.  e.g., they can avoid complaining about `ctypes.WinDLL` not
existing on Linux if its use is guarded by a `sys.platform` check.

Test Plan:
Ran tests on Linux, and will check CI test results.

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Feb 5, 2021

💊 CI failures summary and remediations

As of commit 46fc0bb (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Summary:
Check if we are on Windows using `sys.platform` rather than
`platform.system()`.  Even though `platform.system()` is more modern, it
has a few downsides: this performs a runtime check of the platform type,
which has non-zero overhead.  On Linux it actually executes the separate
`/bin/uname` process.  On the other hand `sys.platform` is determined
when the Python interpreter is compiled, so this is a simple hard-coded
string.

Because it is a runtime check, `platform.system()` checks also cannot be
analyzed by static type checkers like Pyre and Mypy.  These type
checkers do understand `sys.platform` checks, and can correctly avoid
complaining about code paths that use platform-specific modules and
functions.  e.g., they can avoid complaining about `ctypes.WinDLL` not
existing on Linux if its use is guarded by a `sys.platform` check.

Test Plan:
Ran tests on Linux, and will check CI test results.

Differential Revision: [D26271724](https://our.internmc.facebook.com/intern/diff/D26271724)

[ghstack-poisoned]
Summary:
Check if we are on Windows using `sys.platform` rather than
`platform.system()`.  Even though `platform.system()` is more modern, it
has a few downsides: this performs a runtime check of the platform type,
which has non-zero overhead.  On Linux it actually executes the separate
`/bin/uname` process.  On the other hand `sys.platform` is determined
when the Python interpreter is compiled, so this is a simple hard-coded
string.

Because it is a runtime check, `platform.system()` checks also cannot be
analyzed by static type checkers like Pyre and Mypy.  These type
checkers do understand `sys.platform` checks, and can correctly avoid
complaining about code paths that use platform-specific modules and
functions.  e.g., they can avoid complaining about `ctypes.WinDLL` not
existing on Linux if its use is guarded by a `sys.platform` check.

Test Plan:
Ran tests on Linux, and will check CI test results.

Differential Revision: [D26271724](https://our.internmc.facebook.com/intern/diff/D26271724)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

@simpkins merged this pull request in db6e0c7.

@facebook-github-bot facebook-github-bot deleted the gh/simpkins/2/head branch February 15, 2021 15:18
xsacha pushed a commit to xsacha/pytorch that referenced this pull request Mar 31, 2021
Summary:
Pull Request resolved: pytorch#51766

Check if we are on Windows using `sys.platform` rather than
`platform.system()`.  Even though `platform.system()` is more modern, it
has a few downsides: this performs a runtime check of the platform type,
which has non-zero overhead.  On Linux it actually executes the separate
`/bin/uname` process.  On the other hand `sys.platform` is determined
when the Python interpreter is compiled, so this is a simple hard-coded
string.

Because it is a runtime check, `platform.system()` checks also cannot be
analyzed by static type checkers like Pyre and Mypy.  These type
checkers do understand `sys.platform` checks, and can correctly avoid
complaining about code paths that use platform-specific modules and
functions.  e.g., they can avoid complaining about `ctypes.WinDLL` not
existing on Linux if its use is guarded by a `sys.platform` check.
ghstack-source-id: 121107705

Test Plan: Ran tests on Linux, and will check CI test results.

Reviewed By: mraway

Differential Revision: D26271724

Pulled By: simpkins

fbshipit-source-id: b86e427e4ceec0324464ba4bc88b95d5813172d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants