Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There appear to be 1 leaked semaphore objects to clean up at shutdown #720

Open
RabiyaF opened this issue Nov 24, 2024 · 3 comments
Open

Comments

@RabiyaF
Copy link

RabiyaF commented Nov 24, 2024

  • CodeCarbon version: 2.8.0
  • Python version: 3.10.15
  • Operating System: Mac OS (Sequoia)

Description

We were using codecarbon 2.6.0 for fitbenchmarking and this was working fine.

We then updated to 2.7.1 and were seeing the"EmissionsTracker" object has no attribute '_scheduler' error.

Today, I updated the codecarbon dependency to test the latest version 2.8.0. Everything seems to work okay. But if I do a KeyboardInterrupt, I see the following warning:

UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

If I downgrade to codecarbon 2.6.0 and do a KeyboardInterrupt I do not see this warning. I see the normal stack trace of the KeyboardInterrupt.

Question: Has something been updated recently that might be causing this warning ?

@benoit-cty
Copy link
Contributor

Hello,
Thanks for reporting this and using CodeCarbon.

It may have been introduced by https://github.com/mlco2/codecarbon/pull/701/files
Maybe it is because the scheduler is not stopped properly in this case ? @inimaz do you have an idea ?

But I don't see the message you mention when I do a Ctrl+C, can you tell me more on how you get it ?

@inimaz
Copy link
Contributor

inimaz commented Nov 26, 2024

Hi!
Thanks for using Codecarbon!
Indeed as @benoit-cty suggested it could be this feature. Could you provide a snippet of how you are using codecarbon + some more logs? Otherwise I think it is hard to tell.
Thanks!

@RabiyaF
Copy link
Author

RabiyaF commented Nov 26, 2024

We are using codecarbon v2.6.0 like this

tracker = EmissionsTracker(measure_power_secs=1)
tracker.start_task()
"""
our computations go here
"""
energy = tracker.stop_task().energy_consumed

With v2.6.0 I see this in the logs when I do a KeyboardInterrupt. I think this is the stack trace that I would expect with a KeyboardInterrupt.

Running NIST average_difficulty problem set with scipy minimizers 

Running the benchmarking on the NIST_average_difficulty problem set
Password:
Parsing problems
Running problems
                                                                                                                                                                                                        
#################################
 Running data from: ENSO.dat 1/9                                                                                                                                                                        
#################################                                                                                                                                                                       
    Starting value: 1/2                                                                                                                                                                                 
        Cost Function: weighted_nlls                                                                                                                                                                    
            Software: SCIPY                                                                                                                                                                             
                Minimizer: Nelder-Mead                                                                                                                                                                  
Captured output:                                                                                                                                                                                        
ref: /Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/data/private_infra/global_energy_mix.json                                                                   
ref: /Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/data/private_infra/global_energy_mix.json

                Minimizer: Powell                                                                                                                                                                       
Benchmark problems:   0%|                                                                                                                                          | 0/9 [00:06<?, ?Benchmark problem/s^Captured output:                                                                                                                                                                                        
ref: /Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/data/private_infra/global_energy_mix.json                                                                   

Benchmark problems:   0%|                                                                                                                                          | 0/9 [00:08<?, ?Benchmark problem/s]
Traceback (most recent call last):                                                                                                                                                                      
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/bin/fitbenchmarking", line 8, in <module>
    sys.exit(main())
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/cli/main.py", line 562, in main
    run(
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/cli/exception_handler.py", line 29, in wrapped
    return f(*args, **kwargs)
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/cli/main.py", line 410, in run
    results, failed_problems, unselected_minimizers = fit.benchmark()
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/core/fitting_benchmarking.py", line 144, in benchmark
    results = self.__loop_over_starting_values(problem)
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/core/fitting_benchmarking.py", line 203, in __loop_over_starting_values
    result = self.__loop_over_cost_function(problem)
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/core/fitting_benchmarking.py", line 243, in __loop_over_cost_function
    result = self.__loop_over_fitting_software(cost_func)
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/core/fitting_benchmarking.py", line 297, in __loop_over_fitting_software
    result, minimizer_failed = self.__loop_over_minimizers(
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/core/fitting_benchmarking.py", line 364, in __loop_over_minimizers
    result = self.__loop_over_jacobians(controller)
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/core/fitting_benchmarking.py", line 416, in __loop_over_jacobians
    result = self.__loop_over_hessians(controller)
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/core/fitting_benchmarking.py", line 480, in __loop_over_hessians
    accuracy, runtimes, energy = self.__perform_fit(controller)
  File "/Users/<usrpath>/Desktop/Github/Work/fitbenchmarking/fitbenchmarking/core/fitting_benchmarking.py", line 533, in __perform_fit
    energy = tracker.stop_task().energy_consumed / num_runs
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/emissions_tracker.py", line 503, in stop_task
    self._measure_power_and_energy()
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/emissions_tracker.py", line 758, in _measure_power_and_energy
    self._do_measurements()
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/emissions_tracker.py", line 735, in _do_measurements
    f"{hardware.__class__.__name__} : {hardware.total_power().W:,.2f} "
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/external/hardware.py", line 455, in total_power
    return self._get_power()
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/external/hardware.py", line 427, in _get_power
    all_details: Dict = self._interface.get_details()
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/core/powermetrics.py", line 143, in get_details
    self._log_values()
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/site-packages/codecarbon/core/powermetrics.py", line 126, in _log_values
    returncode = subprocess.call(cmd, universal_newlines=True)
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/subprocess.py", line 347, in call
    return p.wait(timeout=timeout)
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/subprocess.py", line 1209, in wait
    return self._wait(timeout=timeout)
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/subprocess.py", line 1959, in _wait
    (pid, sts) = self._try_wait(0)
  File "/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/subprocess.py", line 1917, in _try_wait
    (pid, sts) = os.waitpid(self.pid, wait_flags)
KeyboardInterrupt

With v2.8.0 I see this in the logs when I do a KeyboardInterrupt

Running NIST average_difficulty problem set with scipy minimizers 

Running the benchmarking on the NIST_average_difficulty problem set
Password:
Parsing problems
Running problems
                                                                                                                                                                                                        
#################################
 Running data from: ENSO.dat 1/9                                                                                                                                                                        
#################################                                                                                                                                                                       
    Starting value: 1/2                                                                                                                                                                                 
        Cost Function: weighted_nlls                                                                                                                                                                    
            Software: SCIPY                                                                                                                                                                             
                Minimizer: Nelder-Mead                                                                                                                                                                  
                Minimizer: Powell                                                                                                                                                                       
^C%
/Users/<usrpath>/mambaforge/envs/mantid_env/lib/python3.10/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

Let me know if any other information is required. I will try to see if it is something from our codebase that is causing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants