Mailing List Archive

a clean exit
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.
--
https://mail.python.org/mailman/listinfo/python-list
Re: a clean exit [ In reply to ]
jak wrote at 2021-7-23 10:55 +0200:
> ...
>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.

"Connection reset by peer" means that the other end of the connection
(the so called "peer") has closed the connection.
You will need to open a new connection (as the old one can no longer
be used).
--
https://mail.python.org/mailman/listinfo/python-list
Re: a clean exit [ In reply to ]
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
Re: a clean exit [ In reply to ]
jak wrote at 2021-7-29 00:07 +0200:
> ...
>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.

I assume that you are using a class deriving from a library class
where your application is defined by methods on this class.
Look at the library class's code. Almost surely, the error
in handled by one of its methods. Override this method in
your class as necessary.

--
Dieter
--
https://mail.python.org/mailman/listinfo/python-list