URL에서 일부 JSON을 가져 와서 처리하고, 데이터가 크게 변경되면 알려주는 Python 3 스크립트가 있습니다. 나는 notify2과 PyGObject의 libnotify 바인딩 (gi.repository.Notify)을 사용해 보았으며 두 가지 방법으로 비슷한 결과를 얻었습니다. 이 스크립트는 터미널에서 실행할 때 a-ok로 작동하지만 cron이 실행하려고 할 때 찌를 때 사용합니다. 내가 문자열 목록으로 notify_pygobject
를 호출하는 스크립트를 작성하는 경우libnotify를 사용하는 Python 3 스크립트가 cron 작업으로 실패합니다.
import notify2
from gi.repository import Notify
def notify_pygobject(new_stuff):
Notify.init('My App')
notify_str = '\n'.join(new_stuff)
print(notify_str)
popup = Notify.Notification.new('Hey! Listen!', notify_str,
'dialog-information')
popup.show()
def notify_notify2(new_stuff):
notify2.init('My App')
notify_str = '\n'.join(new_stuff)
print(notify_str)
popup = notify2.Notification('Hey! Listen!', notify_str,
'dialog-information')
popup.show()
이제 cron은 메일 스풀을 통해 나를 다시이 오류가 발생합니다 :
Traceback (most recent call last):
File "/home/p0lar_bear/Documents/devel/notify-test/test1.py", line 3, in <module>
main()
File "/home/p0lar_bear/Documents/devel/notify-test/test1.py", line 4, in main
testlib.notify(notify_projects)
File "/home/p0lar_bear/Documents/devel/notify-test/testlib.py", line 8, in notify
popup.show()
File "/usr/lib/python3/dist-packages/gi/types.py", line 113, in function
return info.invoke(*args, **kwargs)
gi._glib.GError: Error spawning command line `dbus-launch --autolaunch=776643a88e264621544719c3519b8310 --binary-syntax --close-stderr': Child process exited with code 1
... 그리고 나는 그것을 변경하는 경우 대신 notify_notify2()
전화 :
Traceback (most recent call last):
File "/home/p0lar_bear/Documents/devel/notify-test/test2.py", line 3, in <module>
main()
File "/home/p0lar_bear/Documents/devel/notify-test/test2.py", line 4, in main
testlib.notify(notify_projects)
File "/home/p0lar_bear/Documents/devel/notify-test/testlib.py", line 13, in notify
notify2.init('My App')
File "/usr/lib/python3/dist-packages/notify2.py", line 93, in init
bus = dbus.SessionBus(mainloop=mainloop)
File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 211, in __new__
mainloop=mainloop)
File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 100, in __new__
bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 122, in __new__
bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
을 나는 (몇 가지 조사를하고 제안을 내 crontab을에 PATH=
을 넣어, 또는 $DISPLAY
을 수출했다 나는 스크립트 내에서 os.system('export DISPLAY=:0')
로 전화하여이 작업을 수행했으나 아무 변화도 없었습니다 ...
cron 작업 자체에 내보내기를 추가하여 수정했습니다! 고맙습니다! 또한 나는이 스크립트를 실행 파일 python 3.x에서 보통 사용한다고 생각했다 :'#!/usr/bin/env python3' –