Atexit Python package functionality broken in Maya?

Does the atexit package work from within Maya Python?

I’ve tried the straightforward approach:

import sendit

import atexit

where the sendit.sendit() function just sends me an e-mail. I don’t get an e-mail from either Maya2011 or 2012.

There’s a finalize() function registered with atexit in Autodesk\Maya20nn\Python\lib\site-packages\maya\app\startup\, so you’d think it would work. However the finalize() method doesn’t actually do anything, so no one probably noticed whether it works or not. I’ve also tried putting my sendit() call in the Maya finalize() method and got nothing (which is what leads me to think it doesn’t work).

Is this just broken or is there some trick to getting it to work?


— David

Never tried atexit, but if you need something before Maya closes you can use:

with the flag kMayaExiting

Thanks for the info. I figured the API probably had something to help me out - thanks for the specific pointer.

The code that’s calling atexit is in a 3rd party package (PyCuda’s autoinit). I can certainly modify it, but it also needs to run in Python outside of Maya and I just don’t want to clutter the code with conditionals to handle two the different cases unless I have to.

Looking like I may have to though.

— David

I’m really unclear what the scenario is and what this question is asking? Can you lay it out more clearly?

Also you’ll have to deal with the unfortunate fact that there may be some amount of special behaviour that needs to be supported for things to run in Maya (or any non-standard environment), especially for ‘magic’ things that happen ‘automagically’ or assume anything about the running environment.

In short:
[li]The atexit package in python allows you to specify exit handlers that are run at normal interpreter exit.
[/li][li]Maya has the atexit package as part of it’s shipped packages.
[/li][li]Maya even calls it in it’s own Python startup code.
[/li][li]If I register a callback function with atexit.register(), it doesn’t get called when Maya shuts down.
[/li][li]There is a Maya API function that does the same thing and is a possible replacement.
[/li][li]I’m reluctant to use the API unless I have to as the Python code that registers the callback should run both inside Maya and out and code like that is ugly (or uglier than just calling atexit).
The questions are: Does the atexit functionality even work at all? If so, what’s the magic to make it happen?

I suspect it’s just busted, but thought I’d ask around.

— David

Ahhhh… The key phrase is “normal interpreter,” as you know I’d hardly call Maya a normal interpreter. I haven’t tried the package but I’m a bit intrigued by it, if I end up trying it out I’ll be sure to let you know.

That said, you may be well off creating your own wrapper that just uses the maya API callback (which I know works) for Maya and atexit otherwise, or any other interpreter-specific hacks.

BTW I just realized it was ‘at exit’ and not ‘a texit’.