Mercurial > ift6266
comparison scripts/stacked_dae/utils.py @ 139:7d8366fb90bf
Ajouté des __init__.py dans l'arborescence pour que les scripts puissent être utilisés avec des paths pour jobman, et fait pas mal de modifs dans stacked_dae pour pouvoir réutiliser le travail fait pour des tests où le pretraining est le même.
author | fsavard |
---|---|
date | Mon, 22 Feb 2010 13:38:25 -0500 |
parents | 5c79a2557f2f |
children |
comparison
equal
deleted
inserted
replaced
138:128507ac4edf | 139:7d8366fb90bf |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 from jobman import DD | 3 from jobman import DD |
4 | |
5 # from pylearn codebase | |
6 def update_locals(obj, dct): | |
7 if 'self' in dct: | |
8 del dct['self'] | |
9 obj.__dict__.update(dct) | |
4 | 10 |
5 def produit_croise_jobs(val_dict): | 11 def produit_croise_jobs(val_dict): |
6 job_list = [DD()] | 12 job_list = [DD()] |
7 all_keys = val_dict.keys() | 13 all_keys = val_dict.keys() |
8 | 14 |
21 def test_produit_croise_jobs(): | 27 def test_produit_croise_jobs(): |
22 vals = {'a': [1,2], 'b': [3,4,5]} | 28 vals = {'a': [1,2], 'b': [3,4,5]} |
23 print produit_croise_jobs(vals) | 29 print produit_croise_jobs(vals) |
24 | 30 |
25 | 31 |
32 # taken from http://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python | |
33 """Simple module for getting amount of memory used by a specified user's | |
34 processes on a UNIX system. | |
35 It uses UNIX ps utility to get the memory usage for a specified username and | |
36 pipe it to awk for summing up per application memory usage and return the total. | |
37 Python's Popen() from subprocess module is used for spawning ps and awk. | |
38 | |
39 """ | |
40 | |
41 import subprocess | |
42 | |
43 class MemoryMonitor(object): | |
44 | |
45 def __init__(self, username): | |
46 """Create new MemoryMonitor instance.""" | |
47 self.username = username | |
48 | |
49 def usage(self): | |
50 """Return int containing memory used by user's processes.""" | |
51 self.process = subprocess.Popen("ps -u %s -o rss | awk '{sum+=$1} END {print sum}'" % self.username, | |
52 shell=True, | |
53 stdout=subprocess.PIPE, | |
54 ) | |
55 self.stdout_list = self.process.communicate()[0].split('\n') | |
56 return int(self.stdout_list[0]) | |
57 |