-
Notifications
You must be signed in to change notification settings - Fork 0
/
del_mem.py
49 lines (37 loc) · 1.33 KB
/
del_mem.py
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
import pickle, os, sys
from multiprocessing import shared_memory
from make_folder_dict import dateDict
DATE = sys.argv[1]
#folders = pickle.load(open('date_folder_dict.pickle', 'rb'))[DATE]
folders = dateDict()[DATE]
def etreeNumber(e):
for j in e.split('/')[-2].split(('.')):
try: return int(j)
except: pass
def deleteShms():
shmnames = []
for d in folders:
files = [os.path.join(d, f) for f in os.listdir(d) if f.lower().endswith(('flac', 'mp3', 'shn'))]
for i, f in enumerate(files):
etree_number = etreeNumber(f)
shmname = '{0}_{1}'.format(etree_number, i)
shmnames.append(shmname)
#print(shmname)
for t in ['audio', 'hpcp', 'chroma']:
try:
shm = shared_memory.SharedMemory(name=shmname + '_' + t)
shm.close()
shm.unlock()
except: pass
#pickle.dump(shmnames, open('shmnames.pickle', 'wb'))
def deleteShms2():
shmnames = pickle.load(open('shmnames.pickle', 'rb'))
for shmname in shmnames:
for t in ['audio', 'hpcp', 'chroma']:
try:
shm = shared_memory.SharedMemory(name=shmname + '_' + t)
shm.close()
shm.unlock()
except: pass
deleteShms()
#deleteShms2()