'Compiled too binary Python application crashes with this error: Bus error (core dumped)
Problem:
My application crashes with this error: Bus error (core dumped) when I press the shutdown button in the app, but it works as expected running in Pycharm and shuts-down the computer.
Description:
I'm using Python3 and I compiled the code into a binary with Nuitka which:
Nuitka translates the Python modules into a C level program that then uses libpython and static C files of its own to execute in the same way as CPython does.
Here is the Python code in question, the code is suppose to shutdown the system and turn-off the computer:
from pydbus import SystemBus
def shutdown_system():
bus = SystemBus()
proxy = bus.get('org.freedesktop.login1', '/org/freedesktop/login1')
if proxy.CanPowerOff() == 'yes':
proxy.PowerOff(False) # False for 'NOT interactive'
My system is Fedora 34 and I've set the app too run on startup, but it crashes still when run from a terminal.
Questions:
What is the cause?
Can I use this method, and there is something else wrong here, maybe problem with the
Nuitkacompiling?How can I shutdown the system in
Pythonif this is not the right method?
EDIT #1 (gdb run on dump):
If I run python3 main.py the app works and the shutdown feature works as expected.
I'm not sure if this is the core dump but here goes:
root /home/hstefansson # gdb -c /var/lib/systemd/coredump/core.main\\x2ebin.1000.c8be2aa0de294e928f886547bbdc6d44.7775.1647193485000000 ./PycharmProjects/programAfi/main.bin
GNU gdb (GDB) Fedora 11.1-5.fc34
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./PycharmProjects/programAfi/main.bin...
(No debugging symbols found in ./PycharmProjects/programAfi/main.bin)
[New LWP 7775]
[New LWP 7853]
[New LWP 7852]
[New LWP 7776]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./PycharmProjects/programAfi/main.bin'.
Program terminated with signal SIGBUS, Bus error.
#0 0x0000000000a65354 in ?? ()
[Current thread is 1 (Thread 0x7fc288b4d740 (LWP 7775))]
Missing separate debuginfos, use: dnf debuginfo-install bzip2-libs-1.0.8-6.fc34.x86_64 cairo-1.17.4-3.fc34.x86_64 cairo-gobject-1.17.4-3.fc34.x86_64 expat-2.4.4-1.fc34.x86_64 fontconfig-2.13.94-2.fc34.x86_64 freetype-2.10.4-3.fc34.x86_64 glibc-2.33-21.fc34.x86_64 gobject-introspection-1.68.0-4.fc34.x86_64 graphite2-1.3.14-7.fc34.x86_64 harfbuzz-2.7.4-3.fc34.x86_64 libX11-1.7.2-3.fc34.x86_64 libXau-1.0.9-6.fc34.x86_64 libXcursor-1.2.0-5.fc34.x86_64 libXext-1.3.4-6.fc34.x86_64 libXfixes-6.0.0-1.fc34.x86_64 libXft-2.3.3-6.fc34.x86_64 libXrender-0.9.10-14.fc34.x86_64 libbrotli-1.0.9-4.fc34.x86_64 libffi-3.1-28.fc34.x86_64 libmount-2.36.2-1.fc34.x86_64 libpng-1.6.37-10.fc34.x86_64 libselinux-3.2-1.fc34.x86_64 libuuid-2.36.2-1.fc34.x86_64 libxcb-1.13.1-7.fc34.x86_64 libxml2-2.9.13-1.fc34.x86_64 openssl-libs-1.1.1l-2.fc34.x86_64 pcre-8.44-3.fc34.1.x86_64 pixman-0.40.0-3.fc34.x86_64 python3-cairo-1.20.1-1.fc34.x86_64 python3-gobject-3.40.1-1.fc34.x86_64 python3-libs-3.9.10-1.fc34.x86_64 python3-tkinter-3.9.10-1.fc34.x86_64 sssd-client-2.5.2-2.fc34.x86_64 tk-8.6.10-6.fc34.x86_64 xz-libs-5.2.5-5.fc34.x86_64 zlib-1.2.11-26.fc34.x86_64
(gdb)
EDIT #2(Tested if working without the binary and the full code):
If I run
python3 main.pythe app works and the shutdown feature works as expected.The full code:
import os
import subprocess
from tkinter import *
from selenium import webdriver
from pydbus import SystemBus
root = Tk()
label1 = Label(root, text="L-E-I-K-I-R")
label2 = Label(root, text="A-N-N-A-Ð!")
button1 = Button(root, padx=50, pady=10, bg="black", fg="white", command=lambda: button_click_website(website='https://kr.is/'),
text="KR!")
button2 = Button(root, padx=50, pady=10, command=lambda: button_click_website(website='https://www.mbl.is'), text="MORGUNBLAÐIÐ!")
button1.grid()
button2.grid()
"""Create Submit Button"""
button3 = Button(root, command=lambda: button_click_enigma(), text="ENIGMA")
button3.grid(row=2, column=0, padx=15, pady=20)
"""Create Submit Button"""
button4 = Button(root, command=lambda: button_click_play_cards(), text="SPILA SPIL", fg="white", bg="blue")
button4.grid(padx=15, pady=20)
"""Create Submit Button"""
button5 = Button(root, command=lambda: button_click_player(), text="LinkinPark Video")
button5.grid(padx=15, pady=20)
button6 = Button(root, command=lambda: button_click_play_pinball(), text="SPILA PINBALL")
button6.grid(padx=15, pady=20)
button7 = Button(root, command=lambda: button_click_website(website='https://www.google.com'), text="Google")
button7.grid(row=6, column=0, padx=15, pady=20)
button8 = Button(root, command=lambda: shutdown_system(), text="SLÖKKVA!!", bg="red")
button8.grid(row=6, column=4, padx=15, pady=20)
button9 = Button(root, command=lambda: button_click_website(website='https://www.youtube.com'), text="MYNDSKEIÐ&VIDEO")
button9.grid(row=2, column=2, padx=15, pady=20)
button10 = Button(root, command=lambda: button_click_website(website='https://www.visir.is'), text="VISIR.IS")
button10.grid(row=4, column=2, padx=15, pady=20)
button11 = Button(root, fg="white", bg="blue", command=lambda: button_click_website(website='https://www.ruv.is'),
text="RÚV")
button11.grid(row=6, column=3, padx=15, pady=20)
button11 = Button(root, fg="black", bg="green",
command=lambda: button_click_website(website='https://www.bylgjan.is'),
text="BYLGJAN")
button11.grid(row=4, column=3, padx=15, pady=20)
def button_click_enigma():
list_files = subprocess.run(["enigma"])
#label2['text'] = str(list_files)
def button_click_play_cards():
list_files = subprocess.run(["kpat"])
#label2['text'] = str(list_files)
def button_click_play_pinball():
list_files = subprocess.run(["pinball"])
#label1['text'] = str(list_files)
def button_click_website(website):
""" handle button click event and output text from entry area"""
driver = webdriver.Firefox(executable_path='/opt/Geckodriver/geckodriver')
driver.get(website)
driver.maximize_window()
def button_click_player():
os.system(f"mpv https://www.youtube.com/watch?v=WNeLUngb-Xg")
def shutdown_system():
bus = SystemBus()
proxy = bus.get('org.freedesktop.login1', '/org/freedesktop/login1')
if proxy.CanPowerOff() == 'yes':
proxy.PowerOff(False) # False for 'NOT interactive'
label1.grid(row=0, column=0)
label2.grid(row=1, column=1)
button1.grid(row=2, column=1)
button2.grid(row=3, column=2)
root.mainloop()
EDIT #3 (command used)
I compiled the binary with this command:
python3 -m nuitka --follow-imports main.py
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
