~ellisonbg/ipython/trunk-dev

« back to all changes in this revision

Viewing changes to IPython/tests/obj_del.py

  • Committer: Brian Granger
  • Date: 2010-01-31 23:57:46 UTC
  • mfrom: (1109.1.113 ipython)
  • Revision ID: ellisonbg@gmail.com-20100131235746-rj81qa8klooepq2m
Merging from upstream trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Test code for https://bugs.launchpad.net/ipython/+bug/239054
2
 
 
3
 
WARNING: this script exits IPython!  It MUST be run in a subprocess.
4
 
 
5
 
When you run the following script from CPython it prints:
6
 
__init__ is here
7
 
__del__ is here
8
 
 
9
 
and creates the __del__.txt file
10
 
 
11
 
When you run it from IPython it prints:
12
 
__init__ is here
13
 
 
14
 
When you exit() or Exit from IPython neothing is printed and no file is created
15
 
(the file thing is to make sure __del__ is really never called and not that
16
 
just the output is eaten).
17
 
 
18
 
Note that if you call %reset in IPython then everything is Ok.
19
 
 
20
 
IPython should do the equivalent of %reset and release all the references it
21
 
holds before exit. This behavior is important when working with binding objects
22
 
that rely on __del__. If the current behavior has some use case then I suggest
23
 
to add a configuration option to IPython to control it.
24
 
"""
25
 
import sys
26
 
 
27
 
class A(object):
28
 
    def __del__(self):
29
 
      print 'object A deleted'
30
 
 
31
 
a = A()
32
 
 
33
 
# Now, we force an exit, the caller will check that the del printout was given
34
 
_ip.IP.ask_exit()