通过Cron作业安排的Python脚本失败

时间:2017-04-15 03:16:22

标签: python cron

上下文 - 我有一个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

如何解决问题?

1 个答案:

答案 0 :(得分:1)

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

  

使用'cvlc'来使用没有接口的vlc。 [000055ed64567cf8] qt4接口错误:无法连接到X服务器

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

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

cvlc就像没有接口和命令行的vlc。试一试,告诉我们!

相关问题