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('cmsserver:10000/MNC/CMC/CPX')
    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")
        count -= 1
    return

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

main_thread = threading.currentThread()
count = 1000
while count:
    logging.debug('Thread: %s,count:%s'%(main_thread.getName(), count))
    #count += 1
    count -= 1


for t in threading.enumerate():
    if t is main_thread:
        continue
    logging.debug('joining %s', t.getName())
    t.join()
