Why did cProfile crash?

What I Did

For github.com/Crozzers/screen_brightness_control/issues/25#issuecomment-3832118702, I attempted to do as stackoverflow.com/revisions/582337/10 advises:

    1. #!/usr/bin/env sh
      python3.15 -m pip install screen_brightness_control
      
    2. Defaulting to user installation because normal site-packages is not writeable
      Collecting screen_brightness_control
        Downloading screen_brightness_control-0.26.0-py3-none-any.whl.metadata (4.6 kB)
      Downloading screen_brightness_control-0.26.0-py3-none-any.whl (35 kB)
      Installing collected packages: screen_brightness_control
      Successfully installed screen_brightness_control-0.26.0
      
      [notice] A new release of pip is available: 25.3 -> 26.0
      [notice] To update, run: python3.15 -m pip install --upgrade pip
      RokeJulianLockhart@Beedell:~$ python3.15 -m pip install --upgrade pip
      Defaulting to user installation because normal site-packages is not writeable
      Requirement already satisfied: pip in ./.local/lib/python3.15/site-packages (25.3)
      Collecting pip
        Downloading pip-26.0-py3-none-any.whl.metadata (4.7 kB)
      Downloading pip-26.0-py3-none-any.whl (1.8 MB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 3.9 MB/s  0:00:00
      Installing collected packages: pip
        Attempting uninstall: pip
          Found existing installation: pip 25.3
          Uninstalling pip-25.3:
            Successfully uninstalled pip-25.3
      Successfully installed pip-26.0
      
    1. #!/usr/bin/env sh
      python3.15
      
    2. Python 3.15.0a5 (main, Jan 14 2026, 00:00:00) [GCC 15.2.1 20251211 (Red Hat 15.2.1-5)] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import screen_brightness_control as sbc
      >>> for monitor in sbc.list_monitors():
      ...     print(monitor, ':', sbc.get_brightness(display=monitor), '%')
      ...     
      Q3279WG5B : [100] %
      >>> sbc.set_brightness(1)
      >>> import cProfile
      >>> cProfile.run(sbc.set_brightness(100))
               2 function calls in 0.000 seconds
      
         Ordered by: standard name
      
         ncalls  tottime  percall  cumtime  percall filename:lineno(function)
              1    0.000    0.000    0.000    0.000 {built-in method builtins.exec}
              1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
      
      
      Traceback (most recent call last):
        File "<python-input-4>", line 1, in <module>
          cProfile.run(sbc.set_brightness(100))
          ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib64/python3.15/profiling/tracing/__init__.py", line 29, in run
          return _Utils(Profile).run(statement, filename, sort)
                 ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib64/python3.15/profiling/tracing/_utils.py", line 13, in run
          prof.run(statement)
          ~~~~~~~~^^^^^^^^^^^
        File "/usr/lib64/python3.15/profiling/tracing/__init__.py", line 112, in run
          return self.runctx(cmd, dict, dict)
                 ~~~~~~~~~~~^^^^^^^^^^^^^^^^^
        File "/usr/lib64/python3.15/profiling/tracing/__init__.py", line 117, in runctx
          exec(cmd, globals, locals)
          ~~~~^^^^^^^^^^^^^^^^^^^^^^
      TypeError: exec() arg 1 must be a string, bytes or code object
      

      abrt didn’t catch it as a misbehaviour.

My Environment

    1. #!/usr/bin/env sh
      rpm -qi python3.15
      
    2. Name        : python3.15
      Version     : 3.15.0~a5
      Release     : 1.fc43
      Architecture: x86_64
      Install Date: Sun 25 Jan 2026 15:02:57 GMT
      Size        : 29543
      Signature   :
                    RSA/SHA256, Fri 16 Jan 2026 17:39:52 GMT, Key ID 829b606631645531
      Source RPM  : python3.15-3.15.0~a5-1.fc43.src.rpm
      Build Date  : Fri 16 Jan 2026 10:30:49 GMT
      Build Host  : buildhw-x86-09.rdu3.fedoraproject.org
      Packager    : Fedora Project
      Vendor      : Fedora Project
      Bug URL     : https://bugz.fedoraproject.org/python3.15
      
    1. #!/usr/bin/env sh
      python3.15 -m pip show screen_brightness_control
      
    2. Name: screen_brightness_control
      Version: 0.26.0
      Location: $HOME/.local/lib/python3.15/site-packages
      Requires: 
      Required-by: 
      

You’re asking it to profile the result of set_brightness, which is probably None.

You likely want to run cProfile.run("sbc.set_brightness(100)") instead - notice the quotes wrapping the code you want to profile (similar to "foo()" in the Stack Overflow post you linked to)

1 Like