diff --git a/python-stopit-ulong-for-thread-id.patch b/python-stopit-ulong-for-thread-id.patch new file mode 100644 index 0000000..6e24986 --- /dev/null +++ b/python-stopit-ulong-for-thread-id.patch @@ -0,0 +1,47 @@ +From 0da7f4fb26b25e5ed1d35dbce43e2e8bc4ca494a Mon Sep 17 00:00:00 2001 +From: Antti Kajander +Date: Sat, 18 Nov 2023 02:02:38 +0200 +Subject: [PATCH] Use ulong for thread id on Python >= 3.7 + +As per https://docs.python.org/3/c-api/init.html#c.PyThreadState_SetAsyncExc +--- + src/stopit/threadstop.py | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/src/stopit/threadstop.py b/src/stopit/threadstop.py +index 37ecb92..a991750 100644 +--- a/src/stopit/threadstop.py ++++ b/src/stopit/threadstop.py +@@ -9,10 +9,16 @@ + """ + + import ctypes ++import sys + import threading + + from .utils import TimeoutException, BaseTimeout, base_timeoutable + ++if sys.version_info < (3, 7): ++ tid_ctype = ctypes.c_long ++else: ++ tid_ctype = ctypes.c_ulong ++ + + def async_raise(target_tid, exception): + """Raises an asynchronous exception in another thread. +@@ -24,13 +30,13 @@ def async_raise(target_tid, exception): + """ + # Ensuring and releasing GIL are useless since we're not in C + # gil_state = ctypes.pythonapi.PyGILState_Ensure() +- ret = ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(target_tid), ++ ret = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid_ctype(target_tid), + ctypes.py_object(exception)) + # ctypes.pythonapi.PyGILState_Release(gil_state) + if ret == 0: + raise ValueError("Invalid thread ID {}".format(target_tid)) + elif ret > 1: +- ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(target_tid), None) ++ ctypes.pythonapi.PyThreadState_SetAsyncExc(tid_ctype(target_tid), None) + raise SystemError("PyThreadState_SetAsyncExc failed") + + diff --git a/python-stopit.changes b/python-stopit.changes index 041ee00..afc436d 100644 --- a/python-stopit.changes +++ b/python-stopit.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Tue Feb 4 15:44:08 UTC 2025 - Atri Bhattacharya + +- Add python-stopit-ulong-for-thread-id.patch: Use ulong for + thread id on Python >= 3.7, upstream commit dda4bd1 + (gh#glenfant/stopit#31). + ------------------------------------------------------------------- Tue Feb 4 11:50:34 UTC 2025 - Atri Bhattacharya diff --git a/python-stopit.spec b/python-stopit.spec index b13fd37..82b12e1 100644 --- a/python-stopit.spec +++ b/python-stopit.spec @@ -1,7 +1,7 @@ # # spec file for package python-stopit # -# Copyright (c) 2025 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2025 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -12,7 +12,8 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# %define modname stopit @@ -25,6 +26,8 @@ URL: https://pypi.python.org/pypi/stopit Source0: https://files.pythonhosted.org/packages/source/s/stopit/stopit-%{version}.tar.gz Source1: https://raw.githubusercontent.com/glenfant/stopit/refs/tags/%{version}/tests.py Source2: https://raw.githubusercontent.com/glenfant/stopit/refs/tags/%{version}/LICENSE +# PATCH-FIX-UPSTREAM +Patch0: https://github.com/glenfant/stopit/commit/dda4bd181d1d29ab1fb22314dc9bde0e3c931abc.patch#/python-stopit-ulong-for-thread-id.patch BuildRequires: %{python_module devel} BuildRequires: %{python_module pip} BuildRequires: %{python_module setuptools} @@ -41,7 +44,7 @@ BuildArch: noarch * two decorators that may stop its decorated callables on timeout. %prep -%autosetup -n %{modname}-%{version} +%autosetup -p1 -n %{modname}-%{version} cp %{SOURCE1} %{SOURCE2} ./ %build