Python Forum
Error when running script on startup in Linux
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when running script on startup in Linux
#1
I'm trying to run a python program to display the screen on an SPI display. I'm on a Raspberry Pi 4 running Ubuntu. Before I run the script, I have to run the terminal command xhost + (something to do with setting the display). To make it run at boot, I put the script in rc.local with the xhost command before it:

export DISPLAY=:0 (set the DISPLAY variable)
xhost +
python3 /home/username/Desktop/SPI_Display.py >/home/username/Desktop/SPI.log 2>&1 & (run the script and send the output to a log file)

It works for about 140 frames, and then prints this:
Error:
XIO: fatal IO error 0 (Success) on X server ":0" after 899 requests (899 known processed) with 0 events remaining.
There is no traceback, it just prints that and stops. What's wrong?

Here's the script:
#!/usr/bin/python3 #imports from PIL import Image, ImageDraw, ImageGrab import os.path import time from Xlib import display import adafruit_rgb_display.st7789 as st7789 import digitalio import board import mss script_dir = os.path.dirname(os.path.abspath(__file__))#script path cursor_image = Image.open(os.path.join(script_dir, "cursor.png"))#get image for cursor cursor_image = cursor_image.resize(((int)(cursor_image.width / 5), (int)(cursor_image.height / 5)))#scale cursor image #set pins cs_pin = digitalio.DigitalInOut(board.CE0) dc_pin = digitalio.DigitalInOut(board.D25) reset_pin = digitalio.DigitalInOut(board.D24) BAUDRATE = 24000000 spi = board.SPI() #display disp = st7789.ST7789( spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE ) def mmsGrab(): #gets screenshot with mss.mss() as sct: for _, monitor in enumerate(sct.monitors[1:], 1): # Get raw pixels from the screen sct_img = sct.grab(monitor) # Create the Image img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX") return(img) width = disp.height height = disp.width while True: start_time = time.time() image = mmsGrab()#grab screenshot #get cursor position cursor_data = display.Display().screen().root.query_pointer()._data cursor_pos = (cursor_data["root_x"], cursor_data["root_y"]) image.paste(cursor_image, cursor_pos, cursor_image) #add cursor to screenshot image = image.resize((240, 135)) #resize to display disp.image(image)#display image #print FPS print("FPS: ", 1.0 / (time.time() - start_time)) print("Display time: ", time.time() - start_time)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error running 'main' Siondonsen 1 683 Jul-29-2025, 05:03 PM
Last Post: deanhystad
  Running script from remote to server invisiblemind 4 1,763 Mar-28-2025, 07:57 AM
Last Post: buran
  Detect if another copy of a script is running from within the script gw1500se 4 2,035 Jan-31-2025, 11:30 PM
Last Post: Skaperen
  help to boot application on computer startup jacksfrustration 3 1,328 Jan-22-2025, 07:43 AM
Last Post: chaebol2th
  [SOLVED] [Linux] Run Python script through cron? Winfried 2 1,998 Oct-19-2024, 06:29 PM
Last Post: Winfried
  Pandas - error when running Pycharm, but works on cmd line zxcv101 2 3,504 Sep-09-2024, 08:03 AM
Last Post: pinkang
  No Internet connection when running a Python script basil_555 8 5,094 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 13,797 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Is possible to run the python command to call python script on linux? cuten222 6 3,273 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  Help Running Python Script in Mac OS emojistickers 0 1,339 Nov-20-2023, 01:58 PM
Last Post: emojistickers

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.