Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'signal' has no attribute 'valid_signals' #600

Closed
Kruptein opened this issue Apr 8, 2022 · 2 comments
Closed

AttributeError: module 'signal' has no attribute 'valid_signals' #600

Kruptein opened this issue Apr 8, 2022 · 2 comments
Labels

Comments

@Kruptein
Copy link

Kruptein commented Apr 8, 2022

Chaquopy version

11.0.0

Devices or emulators where the issue happens

This is on custom hardware running android 9

Relevant parts of your code

if __name__ == "__main__" or __name__ == "android-apk":
    # main()
    app = web.Application()
    app.add_routes([web.get('/', hello)])
    import signal
    print(dir(signal))
    web.run_app(app)

Describe your issue

I was debugging why my server was not spinning up (it was just hanging on an await s.start(), so changed out my main code with the base sample from aiohttp (as can be seen above). It however is crashing upon the signal module not having valid_signals() which I can also observe by the print(dir(signal)) showing a list without the valid_signals function.

If I print sys.version it shows up as 3.8.11 (default, Sep 6 2021, 17:21:11) in logcat. And from the docs python 3.8 should have valid_signals. Curious another signal property that got added in 3.8 strsignal is present in the dir output. So unsure why valid_signals is missing.

2022-04-08 15:29:10.574 6046-6046/com.lastgameboard.game.planarallyserver E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.lastgameboard.game.planarallyserver, PID: 6046
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lastgameboard.game.planarallyserver/com.lastgameboard.game.planarally_server.MainActivity}: com.chaquo.python.PyException: AttributeError: module 'signal' has no attribute 'valid_signals'
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: com.chaquo.python.PyException: AttributeError: module 'signal' has no attribute 'valid_signals'
        at <python>.asyncio.unix_events._check_signal(unix_events.py:174)
        at <python>.asyncio.unix_events.add_signal_handler(unix_events.py:88)
        at <python>.aiohttp.web_runner.setup(web_runner.py:273)
        at <python>.aiohttp.web._run_app(web.py:321)
        at <python>.asyncio.base_events.run_until_complete(base_events.py:616)
        at <python>.aiohttp.web.run_app(web.py:514)
        at <python>.planarserver.<module>(planarserver.py:323)
        at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:219)
        at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:843)
        at <python>.java.android.importer.exec_module(importer.py:532)
        at <python>.java.android.importer.exec_module(importer.py:581)
        at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:671)
        at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:975)
        at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:991)
        at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1014)
        at <python>.importlib.import_module(__init__.py:127)
        at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModuleNative(chaquopy_java.pyx:155)
        at com.chaquo.python.Python.getModuleNative(Native Method)
        at com.chaquo.python.Python.getModule(Python.java:84)
        at com.lastgameboard.game.planarally_server.MainActivity.onCreate(MainActivity.kt:17)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
2022-04-08 15:29:10.585 6046-6046/? I/Process: Sending signal. PID: 6046 SIG: 9
@mhsmith
Copy link
Member

mhsmith commented Apr 8, 2022

Thanks for the report. It looks like this is only a problem on 32-bit ABIs, where we build Python against an older API level which doesn't include the sigfillset function. So if you have the option of switching to a 64-bit ABI, I suggest you do that.

Otherwise, you can put the following workaround at the start of your code:

import signal

def valid_signals():
    return {signal._int_to_enum(x, signal.Signals) for x in range(1, signal.NSIG)}
signal.valid_signals = valid_signals

We'll add this to the next version of Chaquopy.

@mhsmith mhsmith added the bug label Apr 8, 2022
@mhsmith
Copy link
Member

mhsmith commented May 12, 2022

This issue is fixed in Chaquopy 12.0.0. To upgrade, change the Chaquopy version number in your app's top-level build.gradle file.

@mhsmith mhsmith closed this as completed May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants