Function that tries to setup backend, chosen by user, and if failed, setup one of the allowable backends
(new_backend=None)
| 1199 | |
| 1200 | |
| 1201 | def 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 |
no outgoing calls
no test coverage detected