question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scalene doesn't make use of exit codes

See original GitHub issue

I’d expect that scalene <SOMETHING> returns an error code to the calling shell. Instead it always returns 0. This is also an issue when trying to set up CI for the scalene build itself since the scalene <SOMETHING> succeeds even when there is something wrong with building libscalene.so.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
knedlseppcommented, Sep 6, 2021

@knedlsepp Re: packaging scalene for nixpkgs. How did you go with that? We use nixpkgs in our repo and I’d like to pull in scalene as our Python profiler.

I didn’t make a PR for upstream nixpkgs, here’s an excerpt of my private overlay.nix for my initial packaging attempt. I have to admit that I didn’t look much further into it since last year:

self: super: with self;
{
  python2 = python27;
  python27 = super.python27.override { packageOverrides = pythonOverrides; };
  python2Packages = python27Packages;
  python27Packages = super.recurseIntoAttrs (python27.pkgs);

  python3 = python37;
  python3Packages = python37Packages;
  python37 = super.python37.override { packageOverrides = pythonOverrides; };
  python37Packages = super.recurseIntoAttrs (python37.pkgs);
  python38 = super.python38.override { packageOverrides = pythonOverrides; };
  python38Packages = super.recurseIntoAttrs (python38.pkgs);
  python39 = super.python39.override { packageOverrides = pythonOverrides; };
  python39Packages = super.recurseIntoAttrs (python39.pkgs);

  pythonOverrides = python-self: python-super: {
    # Other overrides
    commonmark = python-self.buildPythonPackage rec {
      pname = "commonmark";
      version = "0.9.1";
      src = python-self.fetchPypi {
        inherit pname version;
        sha256 = "0q7d39lm8kcingpmykk5r959hrwwj6v2icyw3mihczxyb749sbs5";
      };
    };

    rich = python-self.buildPythonPackage rec {
      pname = "rich";
      version = "3.0.1";
      src = python-self.fetchPypi {
        inherit pname version;
        sha256 = "11p11kjpjr0z961fl8kvl5dlp37kd27b3j75qxinnvfnpcgjgfdi";
      };
      propagatedBuildInputs = with python-self; [
        pygments
        typing-extensions
        commonmark
        colorama
        pprintpp
      ];
      postPatch = ''
        substituteInPlace setup.py --replace "'pygments>=2.6.0,<3.0.0'" "'pygments'"
      '';
    };
    scalene = python-self.buildPythonPackage rec {
      pname = "scalene";
      version = "0.9.10";
      src = fetchFromGitHub {
        owner = "emeryberger";
        repo = "scalene";
        rev = "8ff5ee7df30a17ffc2824c9f966a6aec9f989c47";
        sha256 = "0s8j0m749ra4jwml1y60hrazwykha07mpg4vsjaqi3hzb5mkajxs";
      };
      preBuild =
        let
          heaplayers-src = fetchFromGitHub {
            owner = "emeryberger";
            repo = "Heap-Layers";
            rev = "a7385e823199cc89fbe6b2dd3251967d1d1677d5";
            sha256 = "1aria9rr9pxmxlzcxifwx3zyqnf9wwl7kyhks24nww6h9pmsf2ld";
          };
        in
        ''
          substituteInPlace heaplayers-make.mk \
            --replace "git clone" "#git clone"
          cp -R ${heaplayers-src} Heap-Layers
          make
          cp libscalene.so scalene/libscalene.so
        '';
      hardeningDisable = [ "all" ];
      nativeBuildInputs = with self; [ clang ];
      NIX_CFLAGS_COMPILE = [ "-fno-builtin-memcpy" ];
      propagatedBuildInputs = with python-self; [
        rich
      ];
    };
  };
}
1reaction
emerybergercommented, Jul 2, 2020

Fixed the first issue with https://github.com/emeryberger/scalene/commit/20beb7003cef2485880420a034637c7479550243; updated on pip. Thanks for the report!

Second issue: so if I understand it, the problem you are describing in the second part is that scalene silently fails to run when its shared library is not present (failing over to doing CPU-only profiling). I’m not sure what the best alternative is here. Isn’t it better to just check for a failed build?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scalene: internal error: unable to find Python allocator ...
When starting scalene (with poetry run python -m scalene my_script.py ), I get the error Scalene: internal error: unable to find Python ...
Read more >
scalene - PyPI
Scalene highlights hotspots (code accounting for significant percentages of CPU time or memory allocation) in red, making them even easier to spot. Scalene...
Read more >
Scalene: a high-performance, high-precision CPU and ...
My personal POV is that the best way to optimize your Python code is to use native code (whether as libraries or through...
Read more >
That time I optimized a Python program by 5000x - Reddit
TL;DR I used our Scalene profiler (pip install scalene) and some math to make an example program run 5000x faster.
Read more >
TALK / Emery Berger / Scalene - YouTube
Scalene is a high-performance CPU and memory profiler for Python that does a number of things that other Python profilers do not and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found