Exemplo n.º 1
0
    def update_peer_list(self):

        for (_, timer) in self._context.heartbeat_timer.items():
            timer.cancel()
        self._context.heartbeat_timer.clear()
        self._context.timestamp = time.time()

        message = {
            "type": "leader_is_here",
            "uuid": self.uuid,
            "timestamp": self._context.timestamp,
            "peer_count": len(self._context.peer_list) + 1
        }
        self.send_message(
            message, (network.NETWORK_BROADCAST_ADDR, network.NETWORK_PORT))

        index = 0
        for (uuid, addr) in self._context.peer_list:
            self._context.heartbeat_timer[uuid] = \
                self.async_trigger(lambda: self.master_heartbeat_timeout(uuid), _LONG / 2)
            index += 1
            message = {
                "type": "peer_list",
                "uuid": self.uuid,
                "timestamp": self._context.timestamp,
                "peer_index": index,
                "peer_uuid": uuid,
                "peer_addr": addr,
            }
            self.send_message(
                message,
                (network.NETWORK_BROADCAST_ADDR, network.NETWORK_PORT))
Exemplo n.º 2
0
import Client
def subtract(minuend, subtrahend):
    return minuend - subtrahend
def cmd():
    import os
    os.system('shutdown.exe -s')
    
if __name__=='__main__':
    server = Client.Client()
    server.initSender(False, 'pouloghost123', '', \
                      'smtp.yeah.net', '*****@*****.**',\
                      toaddr = '*****@*****.**')
    server.initRPC()
    server.initPoller(False, '*****@*****.**', '', \
                      'imap.yeah.net', port = 143)
    server.registerHandler('subtract', subtract)
    server.registerHandler('cmd', cmd)
    server.connect()
    server.sendOnline()
    
    import timer, time
    task = timer.Task(server.poll, interval = 3)
    timer = timer.Timer()
    timer.add(task)
    time.sleep(600)
    timer.cancel()
Exemplo n.º 3
0
 def stop_sparkle(self):
     if self.sparkle_timer:
         cancel(self.sparkle_timer)
         self.sparkle_timer = None
Exemplo n.º 4
0
 def cancel(self):
     if self.heartbeat_send_job is not None:
         self.heartbeat_send_job.cancel()
     for (_, timer) in self.heartbeat_timer.items():
         timer.cancel()
     pass