13
13
from .base import (DistributedPluginBase , report_crash )
14
14
15
15
16
- def run_node (node , updatehash ):
16
+ def run_node (node , updatehash , plugin_args = None ):
17
17
result = dict (result = None , traceback = None )
18
+ try :
19
+ run_memory = plugin_args ['memory_profile' ]
20
+ except Exception :
21
+ run_memory = False
22
+ if run_memory :
23
+ import memory_profiler
24
+ proc = (node .run (), (), {'updatehash' : updatehash })
25
+ mem_mb , retval = memory_profiler .memory_usage (proc , max_usage = True , retval = True )
26
+ result ['result' ] = retval
27
+ node ._interface .real_memory = mem_mb [0 ]/ 1024.0
18
28
try :
19
29
result ['result' ] = node .run (updatehash = updatehash )
20
30
except :
@@ -160,8 +170,9 @@ def _submit_job(self, node, updatehash=False):
160
170
node .inputs .terminal_output = 'allatonce'
161
171
except :
162
172
pass
163
- self ._taskresult [self ._taskid ] = self .pool .apply_async (run_node , (node ,
164
- updatehash ,), callback = release_lock )
173
+ self ._taskresult [self ._taskid ] = self .pool .apply_async (run_node ,
174
+ (node , updatehash , self .plugin_args ),
175
+ callback = release_lock )
165
176
return self ._taskid
166
177
167
178
def _send_procs_to_workers (self , updatehash = False , graph = None ):
@@ -263,4 +274,4 @@ def _send_procs_to_workers(self, updatehash=False, graph=None):
263
274
else :
264
275
break
265
276
266
- logger .debug ('No jobs waiting to execute' )
277
+ logger .debug ('No jobs waiting to execute' )
0 commit comments