我制作了一个用于加密货币交易的机器人,当我手动启动它时它可以正常工作,但是当你自动运行 Ubuntu 服务时,它会启动并出现以下错误:
end at Sun 2022-04-24 14:02:48 UTC. --
: self.run()
: File "/usr/lib/python3.8/threading.py", line 870, in run
: self._target(*self._args, **self._kwargs)
: File "/home/ubuntu/ea_cripto/orion_cript.py", line 120, in analiseAN
: analisador= analiseEstrategica(cliente, 'BRL')
: File "/home/ubuntu/ea_cripto/analiseAtivos.py", line 21, in __init__
: self.Storage= storage(r)
: File "/home/ubuntu/ea_cripto/dbinstancia.py", line 26, in __init__
: self.db= sqlite3.connect('./database.db')
: sqlite3.OperationalError: unable to open database file
: Exception in thread Thread-2:
: Traceback (most recent call last):
: File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
: self.run()
: File "/usr/lib/python3.8/threading.py", line 870, in run
: self._target(*self._args, **self._kwargs)
: File "/home/ubuntu/ea_cripto/orion_cript.py", line 148, in streamTickers
: dadosStorage= storage(x)
: File "/home/ubuntu/ea_cripto/dbinstancia.py", line 26, in __init__
: self.db= sqlite3.connect('./database.db')
: sqlite3.OperationalError: unable to open database file
: Importações efetuadas com sucesso
: algoritimo entrando na parte de execução de funções.
: Exception in thread Thread-3:
: Traceback (most recent call last):
: File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
运行该脚本的服务是:
[Unit]
Description=RoboOrion - Script que inicializa robo Orion cript
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=ubuntu
ExecStartPre=/usr/bin/sleep 30
ExecStart= /usr/bin/python3 /home/ubuntu/ea_cripto/orion_cript.py
[Install]
WantedBy=multi-user.target
该代码由三个线程工作,我已经完成了以下替代方案:
我设置了 10 分钟的睡眠间隔以进行代码初始化。为服务分配 chmod 777 权限我改变了将参数传递给线程函数内的类的方式。我只是害怕对机器人代码造成更多干扰,因为它手动启动时运行良好,所以我不知道还能做什么。如果有人能帮忙,谢谢。