pylink icon indicating copy to clipboard operation
pylink copied to clipboard

Drop dependency on psutil

Open tpambor opened this issue 5 years ago • 3 comments

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

tpambor avatar Apr 08 '20 13:04 tpambor

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 08 '20 13:04 CLAassistant

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.

hkpeprah avatar Apr 14 '20 18:04 hkpeprah

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.

tpambor avatar Apr 14 '20 19:04 tpambor