Force an applet "stay open" to quit when closing session

Hello,

I have an Applet “stay open” which records at short intervals DSL performances in a text file. It runs in the background. When user makes it quit (or if the applet closes itself after a preprogrammed duration), the log file is closed properly before with use of the “on quit” handler. Nothing complicated.

Now I have an issue when user’s session tries to close automatically after a time of inactivity.
The applet refuses to quit, it generates an exception and the session doesn’t close.
Is there an easy AS way to manage this case?

I must mention that there is no issue if user closes its session voluntarily (like Shift-Cmd-Q) while the applet is performing in the background.