I can 't see the error logs for the last two days.
I can 't see the error logs for the last two days.
I see "An error occurred. Please try again." but there is no error log.
why does everyone works fine on my local machine but keeps breaking when i upload onto pythonanywhere? even though I install all libraries?
In Tasks
restart_bot.sh code:
#!/bin/bash
# This script restarts a Python program named telegram_message_parser.py
echo "Restarting bot..."
pid=$(ps -ef | grep "telegram_message_parser.py" | grep -v grep | awk '{print $2}')
if [ -z "$pid" ]; then
echo "Bot is not running"
else
echo "Bot has been terminated"
kill -15 "$pid"
sleep 5
if ps -p "$pid" > /dev/null; then
echo "Bot could not be terminated, forcing kill"
kill -9 "$pid"
fi
fi
echo "Starting bot..."
nohup python3 ./src/telegram_message_parser.py >/dev/null 2>&1 &
if [ "$?" -ne 0 ]; then
echo "Failed to start bot"
else
echo "Bot has been restarted successfully"
fi
I see in the logs that the script runs without errors and outputs a message that the bot has been started, but the bot doesn't actually start running and when I check the console, I don't see it in the processes. Only after I manually run the same script from the console, the bot starts working. What am I doing wrong?
If you want a script to run all the time, you should use our always-on task feature. Our scheduled tasks are intended to run code on schedule -- if a process started by a scheduled task would reach 2h running time (on free account), it will be killed. Our consoles are designed for housekeeping tasks, nor for long-running jobs, too.
Regarding your Bash script (not a Bash expert, but here's my understaing of what happened): because you're putting python3 ./src/telegram_message_parser.py
in the background and redirecting all output to /dev/null
you don't see any errors, if there are any; $?
holds the exit code of the last command to finish, which is not necessarily the exit code of python3 ./src/telegram_message_parser.py
. If you'd like to get exit code of that command, you should rather keep its pid by adding pid=$!
after you run the command, then wait $pid
-- now $?
should show the exit code of the command.