#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time
from threading import Thread,Event

class ct(Thread):
        def __init__(self,i,e1,e2):
                Thread.__init__(self)
                self.i = i           
                #self.w = w          
                self.e1 = e1         
                self.e2 = e2         

        def run(self):
                while 1:
                        self.e1.wait()
                        print self.i  
                        self.e2.set()
                        self.e1.clear()

e1 = Event()
e1.set()
e2 = Event()
e2.clear()
e3 = Event()
e3.clear()

t1 = ct(4,e1,e2)
t2 = ct(1,e2,e3)
t3 = ct(6,e3,e1)
t3.start()
t2.start()
t1.start()