Created
February 29, 2012 03:20
-
-
Save ajdavis/1937323 to your computer and use it in GitHub Desktop.
Attempt to return socket to pool when thread dies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import thread | |
from thread import _local as local | |
import time | |
class Reaper(object): | |
def __init__(self, pool, sock): | |
self.pool = pool | |
self.sock = sock | |
def __del__(self): | |
print 'E.__del__' | |
self.pool.return_socket(self.sock) | |
class Pool(local): | |
reaper = None | |
def return_socket(self, sock): | |
print 'return_socket', sock | |
p = Pool() | |
def run(): | |
sock = 'sock' | |
p.reaper = Reaper(p, sock) | |
print 'doing stuff in thread' | |
time.sleep(1) | |
print 'quitting thread' | |
thread.start_new_thread(run, ()) | |
time.sleep(2) | |
print 'doing stuff on main' | |
time.sleep(1) | |
print 'doing more stuff on main' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment