-
Notifications
You must be signed in to change notification settings - Fork 2
/
datascope_memory_leak
executable file
·75 lines (65 loc) · 1.85 KB
/
datascope_memory_leak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
"""
Example script to demonstrate the memory
leak in the Python interface to Datascope
@author Rob Newman <[email protected]> 858.822.1333
@version 0.1
@license MIT style license
@modified 2011-07-12
@notes 1. Requires demo database
"""
import sys
import os
sys.path.append('%s/local/data/python/antelope' % os.environ['ANTELOPE'])
import datascope
from time import time, gmtime
try:
from guppy import hpy
except ImportError:
print "Cannot load Guppy PE module. Debugging output repressed"
heapy_loaded = False
else:
heapy_loaded = True
# Init heapy
hp = hpy()
fields = ['snet', 'fsta', 'sta', 'chan', 'ondate', 'ctype', 'edepth', 'hang', 'vang']
def update():
"""Print relative memory statistics
and consumption since last cycle
"""
print hp.heap()
hp.setref()
def infinite_loop(dbptr):
"""Make an infinite
loop to demostrate
Python memory blow up
"""
while True:
dbptr.lookup('', 'snetsta', '', '')
dbptr.join('sitechan')
dbptr.sort(('snet','sta'))
dbptr.group('sta')
for i in range(dbptr.query('dbRECORD_COUNT')):
dbptr[3] = i
sub_sta = dbptr.getv('sta')[0]
db_sub = datascope.dbsubset(dbptr, 'sta=~/%s/' % sub_sta)
db_sub.ungroup()
for j in range(db_sub.query('dbRECORD_COUNT')):
db_sub[3] = j
for f in fields:
value = db_sub.getv(f)[0]
if heapy_loaded:
update()
db_sub.free()
dbptr.free()
def main():
"""Open up demo database
tables and group, then
run infinite loop
"""
dbpath = '%s/demo/socalif/db/scdemo' % os.environ['ANTELOPE']
db = datascope.dbopen(dbpath, 'r')
infinite_loop(db)
db.close()
if __name__ == '__main__':
main()