Guest User

Untitled

a guest
Jun 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. Index: repy/emulcomm.py
  2. ===================================================================
  3. --- repy/emulcomm.py (revision 2365)
  4. +++ repy/emulcomm.py (working copy)
  5. @@ -40,6 +40,9 @@
  6. # Armon: Used for getting the constant IP values for resolving our external IP
  7. import repy_constants
  8.  
  9. +# Armon: Used to close file descriptors
  10. +import os
  11. +
  12. # The architecture is that I have a thread which "polls" all of the sockets
  13. # that are being listened on using select. If a connection
  14. # oriented socket has a connection pending, or a message-based socket has a
  15. @@ -864,11 +867,33 @@
  16.  
  17. # Private
  18. def cleanup(handle):
  19. - try:
  20. - comminfo[handle]['socket'].close()
  21. - except:
  22. - pass
  23. + # Get the file descriptor
  24. + file_descriptor = comminfo[handle]['socket'].fileno()
  25.  
  26. + # Mark the socket as closed
  27. + comminfo[handle]['socket'].close()
  28. +
  29. + # Keep attempting to close the file_descriptor until we are successful
  30. + error = True
  31. + while error:
  32. + try:
  33. + os.close(file_descriptor)
  34. + error = False
  35. + except OSError, e:
  36. + # Try to convert the error
  37. + try:
  38. + errname = errno.errorcode[e[0]]
  39. + except:
  40. + errname = None
  41. +
  42. + # If we get a bad file descriptor error, then this FD has already been cleaned
  43. + if errname in ["EBADF", "WSAEBADF"]:
  44. + break
  45. + time.sleep(RETRY_INTERVAL)
  46. + except:
  47. + time.sleep(RETRY_INTERVAL)
  48. +
  49. +
Add Comment
Please, Sign In to add comment