plasma-umass / scalene

Scalene: a high-performance, high-precision CPU, GPU, and memory profiler for Python with AI-powered optimization proposals
Apache License 2.0
12.14k stars 398 forks source link

Scalene on windows10 throws AttributeError - fails to run #237

Open jasonbrackman opened 3 years ago

jasonbrackman commented 3 years ago

Describe the bug Testing Scalene on a simple program will raise an exception with Windows 10 and Python 3.7

To Reproduce Steps to reproduce the behavior:

  1. Save the following program to disk:

from time import sleep for x in range(1_000): if x % 50 == 0: sleep(0.1)

  1. open a cmd line and run the following: scalene test.py

Expected behavior A simple table should appear listing that sleep takes a lot of time.

Actual behavior Exception in thread Thread-1: Traceback (most recent call last): File "c:\program files\python37\lib\threading.py", line 926, in _bootstrap_inner self.run() File "c:\program files\python37\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "c:\program files\python37\lib\site-packages\scalene\scalene_profiler.py", line 304, in timer_thang signal.raise_signal(ScaleneSignals.cpu_signal) AttributeError: module 'signal' has no attribute 'raise_signal'

Scalene: Program did not run for long enough to profile.

Desktop (please complete the following information):

Additional context I've also tried using the following command -- which results in a different exception:

py -3.7 -m scalene test.py

which results in:

ERROR: Calling scalene main function failed: module 'platform' has no attribute 'python_implementation' Traceback (most recent call last): File "C:\Program Files\Python37\lib\site-packages\scalene__main.py", line 6, in main from scalene import scalene_profiler File "C:\Program Files\Python37\lib\site-packages\scalene\scalene_profiler.py", line 60, in from scalene.scalene_statistics import * File "C:\Program Files\Python37\lib\site-packages\scalene\scalene_statistics.py", line 1, in import cloudpickle File "C:\Program Files\Python37\lib\site-packages\cloudpickle\init__.py", line 4, in from cloudpickle.cloudpickle import * # noqa File "C:\Program Files\Python37\lib\site-packages\cloudpickle\cloudpickle.py", line 97, in PYPY = platform.python_implementation() == "PyPy" AttributeError: module 'platform' has no attribute 'python_implementation'

I can import platform and can access the platform.python_implementation() if I manually open a terminal so not quite sure what is going on there.

emeryberger commented 3 years ago

Quick fix is to use Python 3.8; will issue a patch shortly for 3.7!

emeryberger commented 3 years ago

Should be fixed with https://github.com/plasma-umass/scalene/commit/bfa3a2dd5eff6054c6a27d59bed70e0525425725.

Please test by installing via git:

python3 -m pip install -U git+https://github.com/plasma-umass/scalene

jasonbrackman commented 3 years ago

Just had a chance to check -- unfortunately I get the following:

U:>py -m pip install -U git+https://github.com/plasma-umass/scalene Collecting git+https://github.com/plasma-umass/scalene Cloning https://github.com/plasma-umass/scalene to c:\users\brackm~1\appdata\local\temp\pip-req-build-zli4u1bw Running command git clone -q https://github.com/plasma-umass/scalene 'C:\Users\BRACKM~1\AppData\Local\Temp\pip-req-build-zli4u1bw' ERROR: Command errored out with exit status 1: command: 'C:\Program Files\Python37\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\BRACKM~1\AppData\Local\Temp\pip-req-build-zli4u1bw\setup.py'"'"'; file='"'"'C:\Users\BRACKM~1\AppData\Local\Temp\pip-req-build-zli4u1bw\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\BRACKM~1\AppData\Local\Temp\pip-pip-egg-info-ramyq3g3' cwd: C:\Users\BRACKM~1\AppData\Local\Temp\pip-req-build-zli4u1bw\ Complete output (4 lines): WARNING: The wheel package is not available. running egg_info make vendor-deps error: command 'make' failed: No such file or directory

WARNING: Discarding git+https://github.com/plasma-umass/scalene. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

jasonbrackman commented 3 years ago

I made the change locally to the already installed scalene and the tool no longer crashes, but it also doesn't do anything.

Either of the two commands below result in a blank new line instead of the scalene output expected (which I can see works as expected on my Mac):

py -3.7 -m scalene delete.py scalene delete.py

delete.py contains the following:

from time import sleep

for x in range(1_000): if x % 50 == 0: sleep(0.1)

jaltmayerpizzorno commented 3 years ago

Ah, sorry about the build error, @jasonbrackman... Currently the scalene build environment on Windows requires various Unix-style tools, like those available for github actions. I have a note to either fix or document that.

@emeryberger is looking into the "no output" issue, and we're planning to bring out another release (not 1.3.11), so that you can install it from pypi without having to build it.

jaltmayerpizzorno commented 3 years ago

@jasonbrackman, we've unfortunately come full circle: the python 3.7 compatibility change we attempted, as you saw, doesn't work. I've reverted to the code that requires python 3.8, which at least (somewhat) works. This port is really young and incomplete... we'll work to improve that!

I just initiated a 1.3.12 release for all platforms, so that you can install from pypi; again, note that for now, scalene on native Windows will require python 3.8.