tclass.py
35 lines
| 959 B
| text/x-python
|
PythonLexer
Fernando Perez
|
r2414 | """Simple script to be run *twice*, to check reference counting bugs. | ||
Fernando Perez
|
r1851 | |||
Fernando Perez
|
r2414 | See test_run for details.""" | ||
Fernando Perez
|
r1851 | |||
Thomas Kluyver
|
r4731 | from __future__ import print_function | ||
Fernando Perez
|
r2414 | import sys | ||
Fernando Perez
|
r1856 | |||
Fernando Perez
|
r2414 | # We want to ensure that while objects remain available for immediate access, | ||
# objects from *previous* runs of the same script get collected, to avoid | ||||
# accumulating massive amounts of old references. | ||||
Fernando Perez
|
r1856 | class C(object): | ||
def __init__(self,name): | ||||
self.name = name | ||||
Thomas Kluyver
|
r4731 | self.p = print | ||
Thomas Kluyver
|
r3762 | self.flush_stdout = sys.stdout.flush | ||
Fernando Perez
|
r1856 | |||
def __del__(self): | ||||
Thomas Kluyver
|
r4731 | self.p('tclass.py: deleting object:',self.name) | ||
Thomas Kluyver
|
r3762 | self.flush_stdout() | ||
Fernando Perez
|
r2414 | |||
Fernando Perez
|
r1856 | try: | ||
name = sys.argv[1] | ||||
except IndexError: | ||||
pass | ||||
else: | ||||
Fernando Perez
|
r1910 | if name.startswith('C'): | ||
c = C(name) | ||||
Fernando Perez
|
r2414 | |||
#print >> sys.stderr, "ARGV:", sys.argv # dbg | ||||
Fernando Perez
|
r2415 | |||
# This next print statement is NOT debugging, we're making the check on a | ||||
# completely separate process so we verify by capturing stdout: | ||||
Thomas Kluyver
|
r4734 | print('ARGV 1-:', sys.argv[1:]) | ||
Fernando Perez
|
r2494 | sys.stdout.flush() | ||