1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00
Files
libgpiod/bindings/python/tests/helpers.py
Vincent Fazio 9d8940f38f bindings: python: tests: add multi-threaded tests
Add new multi-threaded test cases to ensure the bindings operate as
expected and do not lead to crashes or data corruption.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260527215922.18678-2-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-05-28 10:59:12 +02:00

33 lines
742 B
Python

# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
from __future__ import annotations
import os
import sys
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from types import TracebackType
class LinkGuard:
def __init__(self, src: str, dst: str) -> None:
self.src = src
self.dst = dst
def __enter__(self) -> None:
os.symlink(self.src, self.dst)
def __exit__(
self,
type: type[BaseException] | None,
val: BaseException | None,
tb: TracebackType | None,
) -> None:
os.unlink(self.dst)
def is_free_threaded() -> bool:
return hasattr(sys, "_is_gil_enabled") and not sys._is_gil_enabled()