import time
import threading
#import ctype


class TagCountArgs:
    def __init__(self, category, tags, fields):
        self.category = category
        self.tags = tags
        self.fields = fields

MAX_TAG_COUNT_BUFFER = 100
tagCounts = []

def GetTagCount():
    global tagCounts
    tagCountThisTime = tagCounts
    tagCounts = []
    return tagCountThisTime

def AgentEventAsync(tags, fields):
    global tagCounts
    if len(tagCounts) > MAX_TAG_COUNT_BUFFER:
        return
    tagCounts.append(TagCountArgs(
        category="agent_event",
        tags=tags,
        fields=fields
    ))

def AgentErrorLogEventAsync(logMessage):
    global tagCounts
    if len(tagCounts) > MAX_TAG_COUNT_BUFFER:
        return
    tagCounts.append(TagCountArgs(
        category="agent_event",
        tags={"event":"Error"},
        fields={"log":logMessage}
    ))


if __name__ == "__main__":

    tags = {"example_tag": "example_value"}
    fields = {"example_field": 42}
    agentEventAsync(tags, fields)

    def timeoutTask():
        print "Timeout Task Start"
        time.sleep(100)
        return None

    def nomalTask():
        print "Nomal Task Start"
        return "Nomal Ok"

    tasks = [nomalTask, timeoutTask, nomalTask]

    for task in tasks:
        result = checkTimeoutTask(task, 3)
        print(result)
