mirror of
https://github.com/python/cpython.git
synced 2025-11-13 15:40:05 +00:00
Actually restore the original asyncore socket map by making a copy of the dict
This commit is contained in:
parent
31e08a4df6
commit
aa8796598a
1 changed files with 6 additions and 3 deletions
|
|
@ -872,11 +872,12 @@ class saved_test_environment:
|
||||||
|
|
||||||
def get_asyncore_socket_map(self):
|
def get_asyncore_socket_map(self):
|
||||||
asyncore = sys.modules.get('asyncore')
|
asyncore = sys.modules.get('asyncore')
|
||||||
return asyncore and asyncore.socket_map or {}
|
# XXX Making a copy keeps objects alive until __exit__ gets called.
|
||||||
|
return asyncore and asyncore.socket_map.copy() or {}
|
||||||
def restore_asyncore_socket_map(self, saved_map):
|
def restore_asyncore_socket_map(self, saved_map):
|
||||||
asyncore = sys.modules.get('asyncore')
|
asyncore = sys.modules.get('asyncore')
|
||||||
if asyncore is not None:
|
if asyncore is not None:
|
||||||
asyncore.socket_map.clear()
|
asyncore.close_all(ignore_all=True)
|
||||||
asyncore.socket_map.update(saved_map)
|
asyncore.socket_map.update(saved_map)
|
||||||
|
|
||||||
def resource_info(self):
|
def resource_info(self):
|
||||||
|
|
@ -892,9 +893,11 @@ class saved_test_environment:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
saved_values = self.saved_values
|
||||||
|
del self.saved_values
|
||||||
for name, get, restore in self.resource_info():
|
for name, get, restore in self.resource_info():
|
||||||
current = get()
|
current = get()
|
||||||
original = self.saved_values[name]
|
original = saved_values.pop(name)
|
||||||
# Check for changes to the resource's value
|
# Check for changes to the resource's value
|
||||||
if current != original:
|
if current != original:
|
||||||
self.changed = True
|
self.changed = True
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue