JSON export waits an extra cycle to write and loses the final sample
Describe the bug
JSON export writes the previous sample only when the next export cycle starts. This leaves an empty output file after the first actual export and loses the final sample when Glances exits.
This is separate from the intentional first-iteration warm-up: GlancesStats.export() skips that first iteration, and the JSON exporter then delays its own first sample by another cycle.
Reproduction
On develop b3f1cf008e9ad28eb02e1bb63d74f980683fedf6, with an empty config file:
python -m glances -C empty.conf --export json --export-json-file stats.json \
--stop-after 2 --quiet --disable-plugin all --enable-plugin cpu,memThe command exits successfully but stats.json has zero bytes. --stop-after 2 includes the initialization iteration and one actual export iteration. A real CLI regression reproduces this without mocking plugins or export calls.
Expected behavior
Once an actual export cycle has finished collecting its plugins, write that completed JSON snapshot immediately. The final sample should not depend on a future iteration.
Environment
Glances 4.5.8.dev1, Python 3.12.13/macOS. CPU and memory are the only enabled plugins in the reproduction.
Source: nicolargo/glances