Il 23/07/2021 10:55, jak ha scritto:
Hello everybody,
I wrote a bot for telegram which consists of some processes of which the
main ones are:
- the main process: a list of callback functions
- a second process: managed with a message queue
- a third process: started by the library I use (python-telegram-bot)
which is used for the event/error log ('logging' module).
The problem is that sometimes I get an error from the library (python-
telegram-bot) via logging that my bot has no way of intercepting. The
error is "connection reset by pear" after which my program is no longer
called and I need to restart it. Typically this happens when Telegram
runs an update.
In any case I can know this error because, to write a log in a telegram
channel, I inherit the 'emit' function of the 'logging.Handler' class.
Hoping to have explained clearly enough the context in which the program
receives information about the error (we are inside a process not
launched directly from the main program), my question is: do you have
advice on how I can close my program in the way as clean as possible in
a easy way?

Thanks in advance.

Thanks to both of you for the replies. I know the rules you described to
me for process synchronization but unfortunately, due to the structure
of the library I am using, I cannot apply them. I can't even use
try/except because the library, when the error occurs, displays it with
the loggin libraries and no longer calls any of the callback functions
my program is composed of. To understand when the error occurs, my only
possibility is to intercept the logging, read the error string and,
if it is not one of mine (mine all start with "<program name>:"), to close the program. Following some examples on the web I also configured
a function to handle the error:
'''
dispatcher.add_error_handler(callback=fallback_error,
                             run_async=True)
'''
but unfortunately after getting that error the library seems to hang and doesn't call my callback function. I was actually hoping to get some tricks to shut down all processes as a suggestion. Could I, for example, create a global list containing the ids of the processes I started and then kill each of them? Can it make sense?

ty again
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to