Skip to content

Commit 946aa5e

Browse files
committed
FIX OrderedDict changed to list in choose_backend function
1 parent eba604c commit 946aa5e

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

memory_profiler.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import subprocess
1818
import logging
1919

20-
from collections import OrderedDict
2120

2221
# TODO: provide alternative when multiprocessing is not available
2322
try:
@@ -1012,26 +1011,18 @@ def choose_backend(new_backend=None):
10121011
setup one of the allowable backends
10131012
"""
10141013

1015-
backends = OrderedDict([
1014+
backends = [
10161015
('psutil', has_psutil),
10171016
('posix', os.name == 'posix'),
10181017
('tracemalloc', has_tracemalloc),
10191018
('no_backend', True)
1020-
])
1019+
]
1020+
backends_indices = {b[0]: i for i, b in enumerate(backends)}
10211021

1022-
def move_to_start(d, key):
1023-
"""
1024-
Emulation of OrderedDict.move_to_end(last=False) for old versions of Python
1025-
"""
1026-
items = [(key, d[key])]
1027-
for _key, _value in d.items():
1028-
if _key != key:
1029-
items.append((_key, _value))
1030-
return OrderedDict(items)
10311022
if new_backend is not None:
1032-
backends = move_to_start(backends, new_backend)
1023+
backends.insert(0, backends.pop(backends_indices[new_backend]))
10331024

1034-
for n_backend, is_available in backends.items():
1025+
for n_backend, is_available in backends:
10351026
if is_available:
10361027
global _backend
10371028
_backend = n_backend

0 commit comments

Comments
 (0)