Skip to content

Commit c6a362d

Browse files
Ensure finalization of tasks in order manager at exit
Use weakref.finalize to ensure synchronization of outstanding events at exit.
1 parent f5b80d9 commit c6a362d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

dpctl/utils/_order_manager.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import weakref
12
from collections import defaultdict
23
from contextvars import ContextVar
34

@@ -88,7 +89,16 @@ def __getitem__(self, q: SyclQueue) -> _SequentialOrderManager:
8889
def clear(self):
8990
"""Clear content of internal dictionary"""
9091
_local = self._map.get()
92+
for v in _local.values():
93+
v.wait()
9194
_local.clear()
9295

9396

9497
SequentialOrderManager = SyclQueueToOrderManagerMap()
98+
99+
100+
def _callback(som):
101+
som.clear()
102+
103+
104+
f = weakref.finalize(SequentialOrderManager, _callback, SequentialOrderManager)

0 commit comments

Comments
 (0)