gpt4 book ai didi

通过 Cron 作业计划的 Python 脚本失败

转载 作者:太空宇宙 更新时间:2023-11-03 15:22:28 25 4
gpt4 key购买 nike

上下文 - 我有一个 Python 脚本,它读取音乐文件夹并每次打开每个音乐文件的 VLC 播放器(将播放一首歌曲,VLC 将关闭,然后另一首将播放,依此类推)。当我从 IDE 或终端执行 python 脚本时,脚本成功运行。但是,当我通过 Cron 作业执行它时,它失败了。

Python 脚本 - 请注意,出于测试目的,我已禁用循环。

import os,subprocess
my_path = '/home/tushar/Music/Devotional/'
songs_list = os.listdir(my_path)
song_str = ''
#for song in songs_list:
#subprocess.run(["vlc", my_path+song])
subprocess.run(["vlc", "/home/tushar/PycharmProjects/Morning Devotional Songs/Ganesha.opus"])

crontab -e

47 10 * * * python3 /home/tushar/PycharmProjects/Morning\ Devotional\ Songs/main.py >> /var/log/myjob.log 2>&1

Cron 作业日志 -

> [000055ed64567cf8] core interface error: no suitable interface module
> [000055ed6445a148] core libvlc error: interface "globalhotkeys,none"
> initialization failed [000055ed64567cf8] dbus interface error: Failed
> to connect to the D-Bus session daemon: Unable to autolaunch a
> dbus-daemon without a $DISPLAY for X11 [000055ed64567cf8] core
> interface error: no suitable interface module [000055ed6445a148] core
> libvlc error: interface "dbus,none" initialization failed
> [000055ed6445a148] core libvlc: Running vlc with the default
> interface. Use 'cvlc' to use vlc without interface. [000055ed64567cf8]
> qt4 interface error: Could not connect to X server [000055ed64567cf8]
> skins2 interface error: cannot initialize OSFactory [000055ed64567cf8]
> [cli] lua interface: Listening on host "*console". VLC media player
> 2.2.4 Weatherwax Command Line Interface initialized. Type `help' for help.
>
> Shutting down. [000055ed64567cf8] [cli] lua interface: Requested
> shutdown. [000055ed64567cf8] [cli] lua interface error: Error loading
> script /usr/lib/vlc/lua/intf/cli.luac: lua/intf/modules/host.lua:279:
> Interrupted. [00007f977c0178c8] core stream error: cannot pre fill
> buffer

如何解决这个问题?

最佳答案

您的 cron 作业日志提供了有关作业失败原因的线索。

Use 'cvlc' to use vlc without interface. [000055ed64567cf8] qt4 interface error: Could not connect to X server

这意味着未找到 y X 服务器,您必须在没有如下界面的情况下运行相同的任务:

subprocess.run(["cvlc", "/home/tushar/PycharmProjects/Morning Devotional Songs/Ganesha.opus"])

cvlc 与没有界面且在命令行上的 vlc 类似。尝试一下并告诉我们!

关于通过 Cron 作业计划的 Python 脚本失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43421818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com