Example #1
0
class CacheManager:
    def __init__(self, fn, port):
        self.fn = fn
        self.server = None
        self.t = None
        self.port = port

    def _reload_cache(self):
        self.fn()

    def _loop(self):
        self.server = socket()
        self.server.bind(('localhost', self.port))
        self.server.listen(1)
        while 1:
            connection, address = self.server.accept()
            value = connection.recv(32)
            if value.strip() == 'clear':
                self._reload_cache()
                connection.send('cleared')
            connection.close()

    def run(self):
        self.t = Thread(target=self._loop)
        self.t.start()
    def kill(self):
        if self.server:
            self.server.close()
        if self.t:
            self.t.kill()
Example #2
0
	s.sendall(random_no+" "+str(len(random_no)))
	a=''
	some=''
      	after=time.time()
	print "communication delay : %f" % (after-before)
	s.close()

      #create threads for different controllers
      thread1 = Thread(target = conn_c1)
      thread2 = Thread(target = conn_c2)
      thread1.start()
      thread2.start() 
      thread1.join()
      thread2.join()
      sleep(20)

    thread = Thread(target = threaded_function)
    
    thread.kill=1
   
    thread.start()
    #thread.join() 
    CLI( net )
    thread.kill=0
    thread.join()
    print "*** Stopping network"
    net.stop()
if __name__ == '__main__':
    setLogLevel( 'info' )  # for CLI output
    multiControllerNet()