1

我使用 Termux 在我的 Android 手机上安装了 python 3.7.3。当我尝试从 python shell 中的多处理导入同步时,我收到上述错误。这是我的代码

from multiprocessing import synchronize 

这是追溯

Traceback (most recent call last):
File "/data/data/com.termux/files/usr/lib/python3.7/multiprocessing/synchronize.py", line 28, in <module>
from _multiprocessing import SemLock, sem_unlink
ImportError: cannot import name 'SemLock' from '_multiprocessing' (/data/data/com.termux/files/home/storage/predictions/env/lib/python3.7/lib-dynload/_multiprocessing.cpython-37m.so)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data/data/com.termux/files/usr/lib/python3.7/multiprocessing/synchronize.py", line 32, in <module>
" synchronization primitives needed will not" +
ImportError: This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.

之后我试图看到提到 3770 问题,但似乎官方网站上的 url 不起作用。谁能帮我解决这个问题

4

2 回答 2

3

除非您是 Android 开发人员,否则此问题无法解决,如错误消息本身所述。

sem_open 是一个用于初始化或打开现有 POSIX 信号量的函数。信号量是线程之间共享的变量,用相当粗略的术语来说它是系统级组件。Android 发行版缺少此组件,因此您无法使用同步。

于 2020-06-15T19:38:19.630 回答
1

我花了很多时间来解决这个问题,并决定在 termux github 页面上打开 bug 报告,并从 termux 开发人员那里获得答案Android supports multiprocessing, but not semaphores. 这里是问题和问答线程的完整解释的链接https://github.com/termux/termux -应用程序/问题/1272

于 2021-03-04T13:10:35.633 回答