시작 시 Python 스크립트 시작

시작 시 Python 스크립트 시작

시작 시 Python 스크립트를 시작하고 싶습니다. 매 시간마다 배경 화면을 자동으로 변경하는 데 사용되는 스크립트입니다 feh --bg-max PATH/to/bg. Arch Linux 및 qtile 창 관리자를 사용합니다. .xinitrc이전에 실행을 시도했지만 exec qtile startqtile이 충돌합니다. 그런 다음 뒤에 넣으면 스크립트가 실행되지 않습니다. 또한 로그인 시 자동으로 실행되도록 startx를 설정했습니다. 터미널에서 정상적으로 실행되면 Python 스크립트가 제대로 작동합니다.

이것은 startx 스크립트입니다:

#
# ~/.bash_profile
#
#Autostart x
[[ -f ~/.bashrc ]] && . ~/.bashrc
if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
    exec startx
fi




편집: 실행하려는 스크립트:


import os
import time
import ctypes
import platform
import random


pictures = ["chemical_nord.png","ign_zorin.png","Nordic-Heroin.png","gnu-linux.png","linux-tux.png","nordtheme.png","Abstract-Nord.png","ign_nordhills.png","Minimal-Nord.png","qyqj7y34hlp31.png","archlinux.png","ign_unsplash10.png","nixos.png","waves.jpg"]


def get_wallpaper():
    number = random.randint(0,13)
    return number




def set_wallpaper():
    system_name = platform.system().lower()
    path = ''
    if system_name == "linux":
        number = get_wallpaper()
        path = "/home/My_Username/Pictures/"+pictures[number]
        command = "feh --bg-max " + path
        os.system(command)


if __name__ == "__main__":
    while(True):
        time.sleep(3600)
        set_wallpaper()



어떻게 작동하게 만들까요?

답변1

시작 시 스크립트를 트리거하려면 다음 내용이 포함된 파일 로 이동하여 /home/$USER/.config/autostart생성하여 수동으로 추가할 수 있습니다..desktop

[Desktop Entry]
Type=Application
Exec=command you wish execute on startup
Name=Name you wish to provide
Comment=comment to describe what the command does

또는 Startup ApplicationLinux 배포판(사용 가능한 경우)에서 애플리케이션을 열고 필요한 세부 정보를 제공하여 항목을 추가할 수 있습니다.

답변2

스크립트가 qtile에 의존하는 경우 qtile 다음에 스크립트를 실행하고 qtile을 사용하여 자동으로 시작해야 합니다.

https://docs.qtile.org/en/latest/manual/config/hooks.html?highlight=autostart#autostart

    import os
import subprocess

from libqtile import hook

@hook.subscribe.startup_once
def autostart():
    home = os.path.expanduser('~/.config/qtile/autostart.sh')
    subprocess.Popen([home])

.xinitrc의 모든 무한 루프 프로세스는 .xinitrc가 완료될 때까지 기다리지 않고 재개할 수 있도록 줄 끝에 &를 추가해야 합니다.

예를 들어 ~/.config/qtile/autostart.sh

        ~/.scripts/my_script.py &

관련 정보