Example #1
0
 def changed(self, control, item):
     if control.get_sensitive():
         if hasattr(control, '_timer'):
             control._timer.cancel()
         control._timer = _Timer(
             0.5, lambda: GLib.idle_add(self._write, control, item))
         control._timer.start()
Example #2
0
 def _changed(control, setting, item, sub_item):
     if control.get_sensitive():
         if hasattr(control, '_timer'):
             control._timer.cancel()
         control._timer = _Timer(
             0.5, lambda: GLib.idle_add(_write, control, setting, item,
                                        sub_item))
         control._timer.start()
Example #3
0
 def start(self, timeout) -> None:
     self.stop()
     with self.__lock:
         self._timer = _Timer(timeout, self.expire)
         self._running = True
         self._expired = False
         self._timer.start()
     return timeout
 def vm_destroy(self, vm, return_resources=True, reason=""):
     
     log.debug("Send shutdown signal to VM %s in StratusLab" % str(vm.id))
     
     if len(reason) > 0:
         log.debug("Reason: %s" % reason)
     
     try:
         StratusLabCluster.__idMap[StratusLabCluster.__vmMap[vm.id]].shutdownInstances([int(vm.id)])
         t = threading._Timer(StratusLabCluster.VM_SHUTDOWN, self.__vm_kill, args=[vm, StratusLabCluster.__idMap[StratusLabCluster.__vmMap[vm.id]]])
         log.debug("Waiting in new thread %s to send kill signal to VM %s in StratusLab" % (str(StratusLabCluster.VM_SHUTDOWN), str(vm.id)))
         t.start()
         self.__cleanKill(vm, return_resources)
         return 0      
     except:
         log.debug("VM with id %s shutdown error in StratusLab" % str(vm.id))
         #import traceback
         #traceback.print_exc()
         
         try:
             self.__vm_kill(vm, StratusLabCluster.__idMap[StratusLabCluster.__vmMap[vm.id]], clean=True, return_resources=return_resources)
             log.debug("Managed to kill VM with id %s in StratusLab" % str(vm.id))
             return 0
         except:
             retry = 3
             while retry > 0:
                 log.debug("Error sending kill signal to VM with id %s, %s trials remaining. Retrying..." % (str(vm.id), str(retry)))
                 time.sleep(5)
                 try:
                     self.__vm_kill(vm, StratusLabCluster.__idMap[StratusLabCluster.__vmMap[vm.id]], clean=True, return_resources=return_resources)
                     log.debug("Managed to kill VM with id %s in StratusLab" % str(vm.id))
                     return 0
                 except:
                     pass
                 retry -= 1
             log.debug("No way, can't destroy VM with id %s in StratusLab. Maybe already destroyed, cleaning..." % str(vm.id))
             self.__cleanKill(vm,False)
             #traceback.print_exc()
             return -1
Example #5
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from sendMail import *
import threading
from time import *


def timeEmail():
    now = str(time.localtime()[3]) + ':' + str(time.localtime()[4])
    if now == '11:30' or now == '17:30':
        pass


timer = threading._Timer(5, timeEmail)
timer.start()
'''
def timeEmail():
    global t    #Notice: use global variable!
    t = threading.Timer(86400.0, outosend)    # 定时器
    t.start()
t = threading.Timer(5.0, outosend)
while 1:
    if time.localtime()[3] == 6:  # 判断现在是不是早晨六点
    t.start()
    break     # 线程不能重复开始,不然会有警告
'''
Example #6
0
def named_timer(name, interval, function, *args, **kwargs):
    timer = _Timer(interval, function, *args, **kwargs)
    timer._name = name
    return timer
Example #7
0
 def _changed(self):
     if self.gtk_range.get_sensitive():
         if self.timer:
             self.timer.cancel()
         self.timer = _Timer(0.5, lambda: GLib.idle_add(self._write))
         self.timer.start()
Example #8
0
def setInterval(timer, task, *args):
    isStop = task()
    if not isStop:
        _Timer(timer, setInterval, [timer, task, args]).start()
Example #9
0
 def changed(self, *args):
     if self.get_sensitive():
         if self.timer:
             self.timer.cancel()
         self.timer = _Timer(0.5, lambda: GLib.idle_add(self.do_change))
         self.timer.start()
Example #10
0
		def _changed(self):
			if self.gtk_range.get_sensitive():
				if self.timer:
					self.timer.cancel()
				self.timer = _Timer(0.5, lambda: GLib.idle_add(self._write))
				self.timer.start()
Example #11
0
    def vm_destroy(self, vm, return_resources=True, reason=""):

        self.log.debug("Send shutdown signal to VM %s in StratusLab",
                       str(vm.id))

        if len(reason) > 0:
            self.log.debug("Reason: %s", reason)

        try:
            StratusLabCluster.__idMap[StratusLabCluster.__vmMap[
                vm.id]].shutdownInstances([int(vm.id)])
            thread = threading._Timer(
                StratusLabCluster.VM_SHUTDOWN,
                self.__vm_kill,
                args=[
                    vm,
                    StratusLabCluster.__idMap[StratusLabCluster.__vmMap[vm.id]]
                ])
            self.log.debug(
                "Waiting in new thread %s to send kill signal to VM %s in StratusLab",
                str(StratusLabCluster.VM_SHUTDOWN), str(vm.id))
            thread.start()
            self.__cleanKill(vm, return_resources)
            return 0
        except:
            self.log.exception("VM with id %s shutdown error in StratusLab",
                               str(vm.id))

            try:
                self.__vm_kill(vm,
                               StratusLabCluster.__idMap[
                                   StratusLabCluster.__vmMap[vm.id]],
                               clean=True,
                               return_resources=return_resources)
                self.log.debug("Managed to kill VM with id %s in StratusLab",
                               str(vm.id))
                return 0
            except:
                retry = 3
                while retry > 0:
                    self.log.debug(
                        "Error sending kill signal to VM with id %s, %s trials remaining. \
                              Retrying...", str(vm.id), str(retry))
                    time.sleep(5)
                    try:
                        self.__vm_kill(vm,
                                       StratusLabCluster.__idMap[
                                           StratusLabCluster.__vmMap[vm.id]],
                                       clean=True,
                                       return_resources=return_resources)
                        self.log.debug(
                            "Managed to kill VM with id %s in StratusLab",
                            str(vm.id))
                        return 0
                    except:
                        pass
                    retry -= 1
                self.log.debug(
                    "No way, can't destroy VM with id %s in StratusLab. \
                          Maybe already destroyed, cleaning...", str(vm.id))
                self.__cleanKill(vm, False)
                return -1
        if pack_num < num_pack:
            seq_num = pack_num * MAXSEGSIZE
            send(ack_port_num, remote_port, seq_num, 0, 0, 0, file_sending[pack_num])
            t_sent[pack_num] = time.time()
            timer.append(threading.Timer(TIME_OUT, timeout, (pack_num,)))
            timer[pack_num%window_size].start()
        else:
            break

    print '******Sending Progress******'

    #Monitoring the sending progress
    while(FINISHED != 2):#When the transmission is not finished
        if FINISHED == 1:#if all the packets has be securely sent, send fin to the receiver to indicate the completion of job
            send(ack_port_num, remote_port, 0, 0, 1, 0, '0')
            timer_fin = threading._Timer(TIME_OUT, send, (ack_port_num, remote_port, 0, 0, 1, 0, '0'))
            timer_fin.start()
        #when sending in progress, display the current sending progress percentage to sender's terminal
        sys.stdout.write('\r'+'             '+str(int(100*round((ack_num/MAXSEGSIZE)/float(num_pack),2)))+'%')
        sys.stdout.flush()

        if FINISHED == 2:#when sending finished:
            timer_fin.cancel()
            print '\n',
            print 'Delivery completed successfully'
            print 'Total bytes sent (and securely received by receiver) = ' + str(ack_num-MAXSEGSIZE)
            print 'Segments sent (and securely received by receiver) = ' + str(num_pack)
            print 'Segments retransmitted = ' + str(retransmit)
            if log_output == 1:
                print 'log information:'
                print logdata