M
M
Maxim2020-07-27 08:12:07
Python
Maxim, 2020-07-27 08:12:07

How to find the cause of its hang in a python script?

Guys, hello.

I have a python script that checks the given mail via IMAP every 10 seconds, and if there is a new message (last id), then it takes the letter to its INBOX folder and from there immediately sends it to my telegram bot. But every two days something happens and letters start to accumulate in the INBOX folder that the script created and, accordingly, the messages stop going to telegrams until I clean this folder.

How can you find the reason for this behavior? Can debugging be enabled? Please share your experiences/options.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-07-27
@MaxRAF

The main.py script itself https://pastebin.com/LSABKQm6
Next to it I have a config.ini file

[email]
host = host.ru #где ищем почту
login = [email protected]
password = 5555555
last_uid = 82 # при первом запуске ID должен сформироваться сам

[telegram]
token = 65785689768769aEGOEYyG2s # бот
chat_id = -40876800 # группа

And I added this script (run.sh) to cron to check mail every 10 seconds. For some reason, if you set the check once every 1 minute, then if there is more than one letter in the INBOX folder, the script will hang. Therefore, I set it every ten seconds, so at least the folder overflows rarely.
run.sh script
#!/usr/bin/env bash
BASEDIR=$(dirname "$0")
echo "START"
source $BASEDIR/send_tickets/bin/activate
python $BASEDIR/main.py

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question