Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/structlog/_utils.py: 46%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# SPDX-License-Identifier: MIT OR Apache-2.0
2# This file is dual licensed under the terms of the Apache License, Version
3# 2.0, and the MIT License. See the LICENSE file in the root of this
4# repository for complete details.
6"""
7Generic utilities.
8"""
10from __future__ import annotations
12import sys
14from contextlib import suppress
15from typing import Any
18def get_processname() -> str:
19 # based on code from
20 # https://github.com/python/cpython/blob/313f92a57bc3887026ec16adb536bb2b7580ce47/Lib/logging/__init__.py#L342-L352
21 processname = "n/a"
22 mp: Any = sys.modules.get("multiprocessing")
23 if mp is not None:
24 # Errors may occur if multiprocessing has not finished loading
25 # yet - e.g. if a custom import hook causes third-party code
26 # to run when multiprocessing calls import.
27 with suppress(Exception):
28 processname = mp.current_process().name
30 return processname