Write the emissions to disk or call the API depending on the configuration, but keep running the experiment. :return: CO2 emissions in kgs
(self)
| 819 | |
| 820 | @suppress(Exception) |
| 821 | def flush(self) -> Optional[float]: |
| 822 | """ |
| 823 | Write the emissions to disk or call the API depending on the configuration, |
| 824 | but keep running the experiment. |
| 825 | :return: CO2 emissions in kgs |
| 826 | """ |
| 827 | # if another instance of codecarbon is already running, Nothing to do here |
| 828 | if ( |
| 829 | hasattr(self, "_another_instance_already_running") |
| 830 | and self._another_instance_already_running |
| 831 | ): |
| 832 | logger.warning( |
| 833 | "Another instance of codecarbon is already running. Exiting." |
| 834 | ) |
| 835 | return |
| 836 | if self._start_time is None: |
| 837 | logger.error("You first need to start the tracker.") |
| 838 | return None |
| 839 | |
| 840 | # Run to calculate the power used from last |
| 841 | # scheduled measurement to shutdown |
| 842 | self._measure_power_and_energy() |
| 843 | |
| 844 | emissions_data = self._prepare_emissions_data() |
| 845 | emissions_data_delta = self._compute_emissions_delta(emissions_data) |
| 846 | |
| 847 | self._persist_data( |
| 848 | total_emissions=emissions_data, delta_emissions=emissions_data_delta |
| 849 | ) |
| 850 | |
| 851 | return emissions_data.emissions |
| 852 | |
| 853 | @suppress(Exception) |
| 854 | def stop(self) -> Optional[float]: |