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

Bug 1842821 - Python: Export the shutdown API #2538

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Rust
* The Ping Rate Limit type is now accessible in the Rust Language Binding ([#2528](https://github.com/mozilla/glean/pull/2528))
* `locale` now exposed through the RLB so it can be set by consumers ([2527](https://github.com/mozilla/glean/pull/2527))
* Python
* Added the shutdown API for Python to ensure orderly shutdown and waiting for uploader processes ([#2538](https://github.com/mozilla/glean/pull/2538))

# v53.1.0 (2023-06-28)

Expand Down
11 changes: 11 additions & 0 deletions glean-core/python/glean/glean.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,16 @@ def handle_client_inactive(cls):
"""
_uniffi.glean_handle_client_inactive()

@classmethod
def shutdown(cls):
"""
Shuts down Glean in an orderly fashion.
"""
_uniffi.glean_shutdown()

# On top of the Glean shutdown
# we also wait for the process dispatcher to finish.
ProcessDispatcher._wait_for_last_process()


__all__ = ["Glean"]
41 changes: 41 additions & 0 deletions glean-core/python/tests/test_glean.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,3 +920,44 @@ def test_max_events_overflow(tmpdir):
assert "testing" == events[0]["category"]
assert "event" == events[0]["name"]
assert 0 == events[0]["timestamp"]


def test_glean_shutdown(safe_httpserver):
"""
In theory we want to test that `Glean.shutdown` here waits for Glean
and any uploader to shut down.
In practice because the process dispatcher runs using multiprocessing
this test will succeed regardless of the `Glean.shutdown` call.
"""

Glean._reset()

custom_ping = PingType(
name="custom", include_client_id=True, send_if_empty=False, reason_codes=[]
)

counter = CounterMetricType(
CommonMetricData(
category="telemetry",
name="counter_metric",
send_in_pings=["custom"],
lifetime=Lifetime.APPLICATION,
disabled=False,
dynamic_label=None,
)
)

Glean._initialize_with_tempdir_for_testing(
application_id=GLEAN_APP_ID,
application_version=glean_version,
upload_enabled=True,
configuration=Configuration(server_endpoint=safe_httpserver.url),
)

for _ in range(10):
counter.add(1)
custom_ping.submit()

Glean.shutdown()
wait_for_requests(safe_httpserver, n=10)
assert 10 == len(safe_httpserver.requests)