1

我正在构建一个适用于 Windows 和 python 的应用程序。它构建正确,这个问题看起来应该在 chaquopy 的 7.0.3 中得到修复;但是它对我不起作用。我已经包含了尝试在 android vm 上运行的 logcat。任何帮助将非常感激。如果需要,我可以包含更多错误消息或来自 logcat 的更多输出。


       // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
        buildscript {
            ext.kotlin_version = "1.4.21"
            repositories {
                google()
                jcenter()
                maven { url "https://chaquo.com/maven" }
            }
            dependencies {
                classpath 'com.android.tools.build:gradle:4.1.1'
                classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
                classpath "com.chaquo.python:gradle:9.1.0"
        
                // NOTE: Do not place your application dependencies here; they belong
                // in the individual module build.gradle files
            }
        }


    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }

当我在android上运行它时它失败了。这是通过 android studio 打印出来的:


    2021-01-05 17:56:53.977 12952-12952/io.emerge.tactileengine E/AndroidRuntime: FATAL EXCEPTION: main
        Process: io.emerge.tactileengine, PID: 12952
        java.lang.RuntimeException: Unable to start activity ComponentInfo{io.emerge.tactileengine/io.emerge.tactileengine.MainActivity}: com.chaquo.python.PyException: ImportError: This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
            at android.app.ActivityThread.-wrap11(Unknown Source:0)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
            at android.os.Handler.dispatchMessage(Handler.java:106)
            at android.os.Looper.loop(Looper.java:164)
            at android.app.ActivityThread.main(ActivityThread.java:6494)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
         Caused by: com.chaquo.python.PyException: ImportError: This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.
    at <python>.multiprocessing.synchronize.<module>(synchronize.py:30)
    at <python>.zipimport.load_module(<frozen zipimport>:259)
    at <python>.java.chaquopy.import_override(import.pxi:60)
    at <python>.multiprocessing.queues.__init__(queues.py:39)
    at <python>.multiprocessing.context.Queue(context.py:103)
    at <python>.top.tactile_engine.setup_unity_comm(tactile_engine.py:67)
    at <python>.top.tactile_engine.run(tactile_engine.py:54)
    at <python>.asyncio.base_events.run_until_complete(base_events.py:612)
    at <python>.asyncio.runners.run(runners.py:43)
    at <python>.top.tactile_engine.main(tactile_engine.py:148)
    at <python>.chaquopy_java.call(chaquopy_java.pyx:281)
    at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:253)
    at com.chaquo.python.PyObject.callAttrThrows(Native Method)
    at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
    at io.emerge.tactileengine.MainActivity.onCreate(MainActivity.kt:33)
    at android.app.Activity.performCreate(Activity.java:7009)
    at android.app.Activity.performCreate(Activity.java:7000)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
    at android.app.ActivityThread.-wrap11(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6494) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
    at com.an

droid.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
4

1 回答 1

1

Chaquopy 7.0.3 和 8.0.1 中的修复是针对在multiprocessing没有实际使用其多进程功能的情况下导入模块的代码。但是,您的代码似乎正在尝试创建一个多进程队列,该队列目前不起作用,因为 Android 不支持 POSIX 信号量。

假设您的应用程序只有一个进程,最简单的解决方案是编辑您的代码以使用multiprocessing.dummy而不是multiprocessing. 或者您可以直接使用单进程queueAPI。

于 2021-01-06T14:06:14.817 回答