Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target: Remove duplicated disconnection logic #710

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions devlib/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,28 +548,23 @@ async def check(**kwargs):
await check(as_root=True)

def disconnect(self):
connections = self._conn.get_all_values()
# Now that we have all the connection objects, we simply reset the TLS
# property so that the connections we got will not be reused anywhere.
del self._conn

unused_conns = self._unused_conns
self._unused_conns.clear()

for conn in itertools.chain(connections, self._unused_conns):
conn.close()
with self._lock:
thread_conns = self._conn.get_all_values()
# Now that we have all the connection objects, we simply reset the
# TLS property so that the connections we obtained will not be
# reused anywhere.
del self._conn

pool = self._async_pool
self._async_pool = None
if pool is not None:
pool.__exit__(None, None, None)
unused_conns = list(self._unused_conns)
self._unused_conns.clear()

with self._lock:
connections = self._conn.get_all_values()
for conn in itertools.chain(connections, self._unused_conns):
for conn in itertools.chain(thread_conns, unused_conns):
conn.close()
if self._async_pool is not None:
self._async_pool.__exit__(None, None, None)

pool = self._async_pool
self._async_pool = None
if pool is not None:
pool.__exit__(None, None, None)

def __enter__(self):
return self
Expand Down