Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop dependency on psutil #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

tpambor
Copy link

@tpambor tpambor commented Apr 8, 2020

The psutil package uses a C extension and therefore cannot be loaded from inside a zip[1]. pylink uses only a single function from psutil which can be easily replaced. If the dependency on psutil is dropped, pylink can be imported from inside a zip.

I have tested on windows and checked that all tests pass with this patch applied.

[1] https://docs.python.org/3/library/zipapp.html#caveats

@CLAassistant
Copy link

CLAassistant commented Apr 8, 2020

CLA assistant check
All committers have signed the CLA.

@hkpeprah
Copy link
Contributor

hkpeprah commented Apr 14, 2020

Sorry for getting back to this so late. Is this code pulled form psutil? Do you know if a later psutil has addressed this issue? It looks like zipapp is a Python3-specific thing? I'd personally prefer not pulling out the code from another open-source package.

@tpambor
Copy link
Author

tpambor commented Apr 14, 2020

The code is not pulled from psutil. For posix compliant platforms it's straightforward to check if the pid is alive. For windows it is a bit more complicated, the implementation is similar to what is outlined here.

It is not a bug in psutil. It is a limitation of python which is unable to load native extensions (dynamic libraries) from a zip file.

zipapp uses Python3. It simplifies the process of packaging an application. The created .pyz package can run on Python2 and Python3. You can find some more details here

The key difference between this implementation and the one provided by psutil is that in this PR ctypes is used on Windows to make the library calls whereas psutil uses a C extension for performance reasons. This is not a concern for pylink as this is not a critical path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants