/usr/share/pyshared/socketpool/backend_thread.py is in python-socketpool 0.5.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | # -*- coding: utf-8 -
#
# This file is part of socketpool.
# See the NOTICE for more information.
import select
import socket
import threading
import time
try:
import Queue as queue
except ImportError: # py3
import queue
Select = select.select
Socket = socket.socket
sleep = time.sleep
Semaphore = threading.BoundedSemaphore
class PriorityQueue(queue.PriorityQueue):
def __iter__(self):
return self
def __next__(self):
try:
result = self.get(block=False)
except queue.Empty:
raise StopIteration
return result
next = __next__
class ConnectionReaper(threading.Thread):
""" connection reaper thread. Open a thread that will murder iddle
connections after a delay """
running = False
def __init__(self, pool, delay=600):
self.pool = pool
self.delay = delay
threading.Thread.__init__(self)
self.setDaemon(True)
def run(self):
self.running = True
while True:
time.sleep(self.delay)
self.pool.murder_connections()
def ensure_started(self):
if not self.running and not self.isAlive():
self.start()
|