Show
Ignore:
Timestamp:
09/09/13 16:08:18 (6 years ago)
Author:
leonwlaw
Message:

Fix for recvmess closing old socket when changing recvmess callback function

* Fixes #1241

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • seattle/trunk/repy/emulcomm.py

    r5640 r6544  
    982982# Armon: How frequently should we check for the availability of the socket? 
    983983RETRY_INTERVAL = 0.2 # In seconds 
     984 
     985 
     986# Private 
     987def safe_delete_handle(handle): 
     988  # Armon: lock the cleanup so that only one thread will do the cleanup, but 
     989  # all the others will block as well 
     990  try: 
     991    handle_lock = comminfo[handle]['closing_lock'] 
     992  except KeyError: 
     993    # Handle a possible race condition, the socket has already been cleaned up. 
     994    return 
     995 
     996  # Acquire the lock 
     997  handle_lock.acquire() 
     998 
     999  try: 
     1000    # Prevent user from using this handle from this point on 
     1001    if handle in comminfo: 
     1002      del comminfo[handle] 
     1003  finally: 
     1004    # Always release the lock 
     1005    handle_lock.release() 
     1006 
     1007 
    9841008 
    9851009# Private 
     
    12721296 
    12731297    # Remove the old entry 
    1274     cleanup(oldhandle) 
     1298    safe_delete_handle(oldhandle) 
    12751299 
    12761300    # We need nanny to substitute the old handle with the new one 
     
    15781602     
    15791603    # Remove the entry for the old socket 
    1580     cleanup(oldhandle) 
     1604    safe_delete_handle(oldhandle) 
    15811605 
    15821606    # Un "tattle" the old handle, re-add the new handle