Skip to content

Commit 1177895

Browse files
committed
improved handling of .destroy
1 parent 09e8ea2 commit 1177895

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

tkthread/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ def _call_from(self):
170170
raise # show the error
171171
finally:
172172
if tres:
173-
self._results.remove(tres)
174173
tres.set(result, error)
174+
self._results.discard(tres)
175175

176176
def _tcl_thread(self):
177177
# Operates in its own thread, with its own Tcl interpreter
@@ -210,9 +210,11 @@ def destroy(self):
210210
Result objects from being set to error.
211211
"""
212212
self._running = False
213-
self._thread_queue.put(None)
213+
self._thread_queue.put(None) # unblock _tcl_thread queue
214214
while self._results:
215-
tr = self._results.pop()
216-
tr.set((RuntimeError, 'destroyed', None),
217-
is_error=True)
218-
215+
try:
216+
tr = self._results.pop()
217+
tr.set((RuntimeError, 'destroyed', None),
218+
is_error=True)
219+
except KeyError:
220+
pass

0 commit comments

Comments
 (0)