Skip to content

Commit

Permalink
Simplify connection closing
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-ryzhov committed Mar 28, 2021
1 parent a605cf1 commit 17cb1f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Changelog
=========

dev
* Simplify connection closing code

1.7.0 (2021-03-22)
------------------

Expand Down
22 changes: 7 additions & 15 deletions src/manhole/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,17 @@ def handle_connection_repl(client):
# Change the switch/check interval to something ridiculous. We don't want to have other thread try
# to write to the redirected sys.__std*/sys.std* - it would fail horribly.
setinterval(2147483647)
try:
client.close() # close before it's too late. it may already be dead
except IOError:
pass
junk = [] # keep the old file objects alive for a bit

for name, fh in backup:
junk.append(getattr(sys, name))
setattr(sys, name, fh)
del backup
for fh in junk:
try:
if hasattr(fh, 'detach'):
fh.detach()
else:
fh.close()
getattr(sys, name).close()
except IOError:
pass
del fh
del junk
setattr(sys, name, fh)
try:
client.close()
except IOError:
pass
finally:
setinterval(old_interval)
_LOG("Cleaned up.")
Expand Down

0 comments on commit 17cb1f2

Please sign in to comment.