com.chaquo.python.PyException: ImportError: This platform lacks a functioning sem_open with multiprocessing

帅比萌擦擦* 提交于 2021-02-10 14:35:23

问题


I am building an application that works on windows and in python. It builds correctly and this issue looks like it should have been fixed in 7.0.3 of chaquopy; however it does not work for me. I have included the logcat from the attempt to run on the android vm. Any help would be really appreciated. I can include more error messages or more output from the logcat if needed.


       // 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
    }

When I run this on android it fails. here is the print out via 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) 

回答1:


The fixes in Chaquopy 7.0.3 and 8.0.1 were for code which imported the multiprocessing module without actually using its multi-process features. However, it looks like your code is trying to create a multi-process queue, which doesn't currently work because Android doesn't support POSIX semaphores.

Assuming your app has only one process, the simplest solution is edit your code to use multiprocessing.dummy instead of multiprocessing. Or you could use the single-process queue API directly.



来源:https://stackoverflow.com/questions/65589550/com-chaquo-python-pyexception-importerror-this-platform-lacks-a-functioning-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!