blob: 374433c68e563534541a080e4e68a74ec894523d [file] [log] [blame]
Andrew Geisslereff27472021-10-29 15:35:00 -05001From bad7e6a625436402a01d03021fb9ccd58bc9930f Mon Sep 17 00:00:00 2001
Andrew Geissler82c905d2020-04-13 13:39:40 -05002From: Alexander Kanavin <alex.kanavin@gmail.com>
3Date: Thu, 9 Jan 2020 17:44:05 +0100
4Subject: [PATCH] setup.py: pass missing libraries to Extension for
5 multiprocessing module
6
7In the following commit:
8...
9commit e711cafab13efc9c1fe6c5cd75826401445eb585
10Author: Benjamin Peterson <benjamin@python.org>
11Date: Wed Jun 11 16:44:04 2008 +0000
12
13 Merged revisions 64104,64117 via svnmerge from
14 svn+ssh://pythondev@svn.python.org/python/trunk
15...
16(see diff in setup.py)
17It assigned libraries for multiprocessing module according
18the host_platform, but not pass it to Extension.
19
20In glibc, the following commit caused two definition of
21sem_getvalue are different.
22https://sourceware.org/git/?p=glibc.git;a=commit;h=042e1521c794a945edc43b5bfa7e69ad70420524
23(see diff in nptl/sem_getvalue.c for detail)
24`__new_sem_getvalue' is the latest sem_getvalue@@GLIBC_2.1
25and `__old_sem_getvalue' is to compat the old version
26sem_getvalue@GLIBC_2.0.
27
28To build python for embedded Linux systems:
29http://www.yoctoproject.org/docs/2.3.1/yocto-project-qs/yocto-project-qs.html
30If not explicitly link to library pthread (-lpthread), it will
31load glibc's sem_getvalue randomly at runtime.
32
33Such as build python on linux x86_64 host and run the python
34on linux x86_32 target. If not link library pthread, it caused
35multiprocessing bounded semaphore could not work correctly.
36...
37>>> import multiprocessing
38>>> pool_sema = multiprocessing.BoundedSemaphore(value=1)
39>>> pool_sema.acquire()
40True
41>>> pool_sema.release()
42Traceback (most recent call last):
43 File "<stdin>", line 1, in <module>
44ValueError: semaphore or lock released too many times
45...
46
47And the semaphore issue also caused multiprocessing.Queue().put() hung.
48
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050049Upstream-Status: Pending
Andrew Geissler82c905d2020-04-13 13:39:40 -050050
51Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
52Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
Andrew Geisslereff27472021-10-29 15:35:00 -050053
Andrew Geissler82c905d2020-04-13 13:39:40 -050054---
55 setup.py | 2 +-
56 1 file changed, 1 insertion(+), 1 deletion(-)
57
58diff --git a/setup.py b/setup.py
Andrew Geisslereff27472021-10-29 15:35:00 -050059index d92face..f42bcbb 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050060--- a/setup.py
61+++ b/setup.py
Andrew Geisslereff27472021-10-29 15:35:00 -050062@@ -1836,7 +1836,7 @@ class PyBuildExt(build_ext):
63 if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
64 sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
65 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
Andrew Geissler82c905d2020-04-13 13:39:40 -050066- self.add(Extension('_multiprocessing', multiprocessing_srcs,
67+ self.add(Extension('_multiprocessing', multiprocessing_srcs, libraries=['pthread'],
68 include_dirs=["Modules/_multiprocessing"]))
69
Andrew Geisslereff27472021-10-29 15:35:00 -050070 if (not MS_WINDOWS and