MCPcopy Index your code
hub / github.com/pythonprofilers/memory_profiler / choose_backend

Function choose_backend

memory_profiler.py:1201–1227  ·  view source on GitHub ↗

Function that tries to setup backend, chosen by user, and if failed, setup one of the allowable backends

(new_backend=None)

Source from the content-addressed store, hash-verified

1199
1200
1201def choose_backend(new_backend=None):
1202 """
1203 Function that tries to setup backend, chosen by user, and if failed,
1204 setup one of the allowable backends
1205 """
1206
1207 _backend = 'no_backend'
1208 all_backends = [
1209 ('psutil', True),
1210 ('psutil_pss', True),
1211 ('psutil_uss', True),
1212 ('posix', os.name == 'posix'),
1213 ('tracemalloc', has_tracemalloc),
1214 ]
1215 backends_indices = dict((b[0], i) for i, b in enumerate(all_backends))
1216
1217 if new_backend is not None:
1218 all_backends.insert(0, all_backends.pop(backends_indices[new_backend]))
1219
1220 for n_backend, is_available in all_backends:
1221 if is_available:
1222 _backend = n_backend
1223 break
1224 if _backend != new_backend and new_backend is not None:
1225 warnings.warn('{0} can not be used, {1} used instead'.format(
1226 new_backend, _backend))
1227 return _backend
1228
1229
1230# Insert in the built-ins to have profile

Callers 6

memory_usageFunction · 0.85
__init__Method · 0.85
profileFunction · 0.85
exec_with_profilerFunction · 0.85
run_module_with_profilerFunction · 0.85
memory_profiler.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected