FAQ
Hi people!


I have asked myself a question, if there is a opposite of "__init__.py"
like "__del__.py" ?!


I want, that when the application ends, certain functions are executed.
I know I could make a constructor and a destructor, but I simply want to
know if there is a opposite....




Thanks






Tamer

Search Discussions

  • Ian Kelly at Aug 19, 2013 at 5:06 pm
    Yes, see the atexit module:


    http://docs.python.org/3/library/atexit.html

    On Mon, Aug 19, 2013 at 10:48 AM, Tamer Higazi wrote:
    Hi people!

    I have asked myself a question, if there is a opposite of "__init__.py"
    like "__del__.py" ?!

    I want, that when the application ends, certain functions are executed.
    I know I could make a constructor and a destructor, but I simply want to
    know if there is a opposite....


    Thanks



    Tamer
    --
    http://mail.python.org/mailman/listinfo/python-list
  • Steven D'Aprano at Aug 19, 2013 at 5:13 pm

    On Mon, 19 Aug 2013 18:48:19 +0200, Tamer Higazi wrote:


    Hi people!

    I have asked myself a question, if there is a opposite of "__init__.py"
    like "__del__.py" ?!

    No. If you want to run code when your application is shutting down, run
    it just before your code finishes:


    def main():
        do_this()
        do_that()




    if __name__ == '__main__':
         main()
         shutdown()




    If you care about code running even if an exception takes place:




    if __name__ == '__main__':
         try:
             main()
         finally:
             shutdown()




    --
    Steven
  • Dave Angel at Aug 19, 2013 at 6:48 pm

    Tamer Higazi wrote:


    Hi people!

    I have asked myself a question, if there is a opposite of "__init__.py"
    like "__del__.py" ?!

    Others have answered your question, but I wanted to correct a
    misunderstanding:

    I want, that when the application ends, certain functions are executed.
    I know I could make a constructor and a destructor,

    Not sure what you're talkiing about, but you cannot be sure that an
    object's destructor ( __del__() ) will ever be called. If you want to
    make sure that a particular object gets processed, one approach is the
    with- syntax.



    but I simply want to
    know if there is a opposite....





    --
    DaveA

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 19, '13 at 4:48p
activeAug 19, '13 at 6:48p
posts4
users4
websitepython.org

People

Translate

site design / logo © 2021 Grokbase