<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import socket <EOL> import gevent <EOL> from gevent . lock import Semaphore <EOL> from gevent . server import StreamServer <EOL> from gevent . util import wrap_errors <EOL> from . import INTERVAL , LOG , PICKLE_PROTOCOL , ProfilingServer <EOL> __all__ = [ '<STR_LIT>' ] <EOL> class GeventProfilingServer ( StreamServer , ProfilingServer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , listener , profiler = None , interval = INTERVAL , <EOL> log = LOG , pickle_protocol = PICKLE_PROTOCOL , ** server_kwargs ) : <EOL> StreamServer . __init__ ( self , listener , ** server_kwargs ) <EOL> ProfilingServer . __init__ ( self , profiler , interval , <EOL> log , pickle_protocol ) <EOL> self . lock = Semaphore ( ) <EOL> def _send ( self , sock , data ) : <EOL> sock . sendall ( data ) <EOL> def _close ( self , sock ) : <EOL> sock . close ( ) <EOL> def _addr ( self , sock ) : <EOL> return sock . getsockname ( ) <EOL> def _start_profiling ( self ) : <EOL> gevent . spawn ( self . profile_periodically ) <EOL> def _start_watching ( self , sock ) : <EOL> disconnected = lambda x : self . disconnected ( sock ) <EOL> recv = wrap_errors ( socket . error , sock . recv ) <EOL> gevent . spawn ( recv , <NUM_LIT:1> ) . link ( disconnected ) <EOL> def profile_periodically ( self ) : <EOL> with self . lock : <EOL> for __ in self . profiling ( ) : <EOL> gevent . sleep ( self . interval ) <EOL> def handle ( self , sock , addr = None ) : <EOL> self . connected ( sock ) </s>
