import random
import threading
import time
import logging
import urllib
from PyTango.gevent import DeviceProxy
#from PyTango import DeviceProxy


logging.basicConfig(level=logging.DEBUG,
                    format=' %(asctime)s %(threadName)-14s: %(message)s',
                    )

def worker():
    """thread worker function"""
    t = threading.currentThread()
    logging.debug("started working %s"%t.getName())
    dev = DeviceProxy('10.29.135.24:10000/MNC/LMC/GSB')
    logging.debug("proxy created by %s"%t.getName())
    count = 25
    while count:
        try:
            logging.debug('Reading attribute Date:')
            logging.debug(dev.Date)
        except:
            logging.debug("Exception occurred while reading")
        count -= 1
    return

"""
Main Thread initiate worker thread 
in which I have created PyTango client for one DS
"""

t = threading.Thread(target=worker)
t.setDaemon(True)
t.start()

main_thread = threading.currentThread()
count = 1000
""" After starting worker Thread, main thread continue it's work i.e doing some repetative task"""
while count:
    logging.debug('Thread: %s,count:%s'%(main_thread.getName(), count))
    #count += 1
    count -= 1

"""Wait for worker thread to complete it's task"""
for t in threading.enumerate():
    if t is main_thread:
        continue
    logging.debug('joining %s', t.getName())
    t.join()
