我想每1分钟运行一次python脚本。脚本运行完美,不会引起任何错误。对于cron作业,我正在使用ThisPython CronTab
I am getting below error while run mycronjob.py file
Traceback (most recent call last):
File "cronstart.py", line 6, in <module>
my_cron.write()
File "/home/myname/.local/lib/python3.6/site-packages/crontab.py", line 338, in write
filed, path = tempfile.mkstemp()
AttributeError: module 'tempfile' has no attribute 'mkstemp'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in
apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in
<module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 20, in <module>
from urllib.error import URLError
File "/usr/lib/python3.6/urllib/error.py", line 14, in <module>
import urllib.response
File "/usr/lib/python3.6/urllib/response.py", line 14, in <module>
class addbase(tempfile._TemporaryFileWrapper):
AttributeError: module 'tempfile' has no attribute '_TemporaryFileWrapper'
Original exception was:
Traceback (most recent call last):
File "cronstart.py", line 6, in <module>
my_cron.write()
File "/home/myname/.local/lib/python3.6/site-packages/crontab.py", line 338, in write
filed, path = tempfile.mkstemp()
`enter code here` AttributeError: module 'tempfile' has no attribute 'mkstemp'
我的cron运行文件代码:
from crontab import CronTab
my_cron = CronTab(user='Myuser name')
job = my_cron.new(command='python3 sample.py')
job.minute.every(1)
my_cron.write()
sample.py只是print(“ Printing cron job”)