Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: repy/emulcomm.py
- ===================================================================
- --- repy/emulcomm.py (revision 2365)
- +++ repy/emulcomm.py (working copy)
- @@ -40,6 +40,9 @@
- # Armon: Used for getting the constant IP values for resolving our external IP
- import repy_constants
- +# Armon: Used to close file descriptors
- +import os
- +
- # The architecture is that I have a thread which "polls" all of the sockets
- # that are being listened on using select. If a connection
- # oriented socket has a connection pending, or a message-based socket has a
- @@ -864,11 +867,33 @@
- # Private
- def cleanup(handle):
- - try:
- - comminfo[handle]['socket'].close()
- - except:
- - pass
- + # Get the file descriptor
- + file_descriptor = comminfo[handle]['socket'].fileno()
- + # Mark the socket as closed
- + comminfo[handle]['socket'].close()
- +
- + # Keep attempting to close the file_descriptor until we are successful
- + error = True
- + while error:
- + try:
- + os.close(file_descriptor)
- + error = False
- + except OSError, e:
- + # Try to convert the error
- + try:
- + errname = errno.errorcode[e[0]]
- + except:
- + errname = None
- +
- + # If we get a bad file descriptor error, then this FD has already been cleaned
- + if errname in ["EBADF", "WSAEBADF"]:
- + break
- + time.sleep(RETRY_INTERVAL)
- + except:
- + time.sleep(RETRY_INTERVAL)
- +
- +
Add Comment
Please, Sign In to add comment