[Idle-dev] Fwd: atexit handler in IDLE?

Steve Spicklemire steve at spvi.com
Thu Jan 17 03:47:47 CET 2013


So how dumb is this? For what it's worth... it works for me.

-steve

aluminum:idlelib steve$ diff -C3  run_orig.py run_new.py 
*** run_orig.py	 2013-01-16 15:31:08.000000000 -0700
--- run_new.py	 2013-01-16 15:30:47.000000000 -0700
***************
*** 308,313 ****
--- 308,316 ----
              if jit:
                  self.rpchandler.interp.open_remote_stack_viewer()
          else:
+             if hasattr(sys,'exitfunc') and sys.exitfunc:
+                 sys.exitfunc()
+                 
              flush_stdout()
  
      def interrupt_the_server(self):


On Jan 16, 2013, at 9:17 AM, Roger Serwy wrote:

> Hi Steve,
> 
> IDLE's subprocess never actually exits, so the atexit handler will not be called. Forcing an exit with sys.exit() will be caught and the subprocess will still not exit.
> 
> I suggest filing a bug at bugs.python.org.
> 
> - Roger
> 
> 
> On 01/16/2013 06:50 AM, Steve Spicklemire wrote:
>> Hello Idle-dev folks,
>> 
>> I tried this on the python list, with no luck. ;-(
>> 
>> I hate to bother you with a basic user question, but I'm not sure where else to go. Is there a better list for this?
>> 
>> thanks,
>> -steve
>> 
>> Begin forwarded message:
>> 
>>> From: Steve Spicklemire <steve at spvi.com>
>>> Subject: atexit handler in IDLE?
>>> Date: January 15, 2013 5:25:34 AM MST
>>> To: python-list at python.org
>>> Cc: Steve Spicklemire <steve at spvi.com>
>>> 
>>> Hello Pythonistas!
>>> 
>>> I'm trying to get this program, which works on the command line, to run correctly in the IDLE environment:
>>> 
>>> import atexit
>>> 
>>> print "This is my program"
>>> 
>>> def exit_func():
>>>    print "OK.. that's all folks!"
>>> 
>>> atexit.register(exit_func)
>>> 
>>> print "Program is ending..."
>>> 
>>> 
>>> When I run this on the command line I see:
>>> 
>>> This is my program
>>> Program is ending...
>>> OK.. that's all folks!
>>> 
>>> When I run this in IDLE I see:
>>> 
>>> This is my program
>>> Program is ending...
>>> 
>>> But the atexit handler is never called. ;-(
>>> 
>>> I tried to fish through the IDLE source to see how the program is actually called, and I decided it looked like it was being invoked with with os.spawnv, but I'm not sure why this would defeat the atexit handler. Anybody know? I'd like to register such a function in my module, but I need it to work in IDLE so that students can easily use it.
>>> 
>>> thanks!
>>> -steve
>>> 
>>> 
>>> 
>> _______________________________________________
>> IDLE-dev mailing list
>> IDLE-dev at python.org
>> http://mail.python.org/mailman/listinfo/idle-dev
> 
> _______________________________________________
> IDLE-dev mailing list
> IDLE-dev at python.org
> http://mail.python.org/mailman/listinfo/idle-dev



More information about the IDLE-dev mailing list