banesullivan / scooby

🐶 🕵️ Great Dane turned Python environment detective
MIT License
47 stars 12 forks source link

Scooby upwards of version 0.5.7 segfaults Python #75

Closed Huite closed 2 years ago

Huite commented 2 years ago

Coming from: https://github.com/pyvista/pyvista/issues/1961

I get an immediate segfault when importing scooby, versions 0.5.8, 0.5.9, and 0.5.10.

I'll try and see if I can narrow it down a little more.

System information, for completeness (collected with 0.5.7 ^^):

--------------------------------------------------------------------------------
  Date: Thu Dec 23 16:28:20 2021 W. Europe Standard Time

                OS : Windows
            CPU(s) : 8
           Machine : AMD64
      Architecture : 64bit
               RAM : 31.9 GiB
       Environment : Python

  Python 3.8.12 | packaged by conda-forge | (default, Oct 12 2021, 21:22:46)
  [MSC v.1916 64 bit (AMD64)]

             numpy : 1.20.3
             scipy : 1.7.3
           IPython : 7.30.1
        matplotlib : 3.5.1
            scooby : 0.5.7
--------------------------------------------------------------------------------
Huite commented 2 years ago

0d1a3fd523d6e191b74874ba1e83757994ddf736 introduces the following lines in scooby.knowledge:

if psutil:
    # Code by https://stackoverflow.com/a/35291824/10504481
    my_path = str(Path(__file__).resolve())
    best_match = ""
    FILESYSTEM_TYPE = ""
    for part in psutil.disk_partitions():
        if my_path.startswith(part.mountpoint) and len(best_match) < len(part.mountpoint):
            FILESYSTEM_TYPE = part.fstype
            best_match = part.mountpoint
else:
    FILESYSTEM_TYPE = False

Turns out this is sufficient to segfault:

import psutil
psutil.disk_partitions()

I'll try some other Python versions on Windows as well.

Huite commented 2 years ago

Python 3.9.9 also crashes for me.

Downgrading psutil from 5.8.0 to 5.7.3 solves the issue for me.

Huite commented 2 years ago

Opened an issue on psutil repo as well:

https://github.com/giampaolo/psutil/issues/2038

banesullivan commented 2 years ago

Thank you for the thorough investigation and opening the upstream issue!

This seems very problematic and I'd like to get a patch in for this ASAP.

I may just add a check for windows after v5.7 to avoid calling the function that seg faults. Do you think that'd be okay?

akaszynski commented 2 years ago

I may just add a check for windows after v5.7 to avoid calling the function that seg faults. Do you think that'd be okay?

That's probably our best bet until this is fixed in psutil.

Huite commented 2 years ago

I just came home from the office, figured I'd have another look: I no longer get the segfault.

Looks like it's due to having a certain USB plugged in: https://github.com/giampaolo/psutil/issues/1953

PR is already merged: https://github.com/giampaolo/psutil/pull/1962

EDIT: on the other hand: https://github.com/giampaolo/psutil/issues/2003 Avoiding disk_partitions on Windows seems like a good idea for now.