# Path: FileHandling.py
# def getCPUTimes(workDir):
#     """ Extract and add up the total CPU times from the job report """
#     # Note: this is used with Event Service jobs
# 
#     # Input:  workDir (location of jobReport.json)
#     # Output: cpuCU (unit), totalCPUTime, conversionFactor
# 
#     totalCPUTime = 0L
# 
#     jobReport_dictionary = getJobReport(workDir)
#     if jobReport_dictionary != {}:
#         if jobReport_dictionary.has_key('resource'):
#             resource_dictionary = jobReport_dictionary['resource']
#             if resource_dictionary.has_key('executor'):
#                 executor_dictionary = resource_dictionary['executor']
#                 for format in executor_dictionary.keys(): # "RAWtoESD", ..
#                     if executor_dictionary[format].has_key('cpuTime'):
#                         try:
#                             totalCPUTime += executor_dictionary[format]['cpuTime']
#                         except:
#                             pass
#                     else:
#                         tolog("Format %s has no such key: cpuTime" % (format))
#             else:
#                 tolog("No such key: executor")
#         else:
#             tolog("No such key: resource")
# 
#     conversionFactor = 1.0
#     cpuCU = "s"
# 
#     return cpuCU, totalCPUTime, conversionFactor


import inspect
import commands
import os
import re
import signal
import sys
import time
import Queue
import multiprocessing
import subprocess
import threading
import json
import traceback
    import yampl
from pandayoda.yodacore import Logger
from FileHandling import getCPUTimes
from signal_block.signal_block import block_sig, unblock_sig
            self.__messageQ = messageQ
            self._stop = threading.Event()
            try:
                self.__messageSrv = yampl.ServerSocket(socketname, context)
            except:
                self.__log.debug("Exception: failed to start yampl server socket: %s" % traceback.format_exc())

        def send(self, message):
            try:
                self.__messageSrv.send_raw(message)
            except:
                self.__log.debug("Exception: failed to send yampl message: %s" % traceback.format_exc())

        def stop(self):
            self._stop.set()

        def stopped(self):
            return self._stop.isSet()

        def __del__(self):
            if self.__messageSrv:
                del self.__messageSrv
                self.__messageSrv = None

        def run(self):
            try:
                while True:
                    if self.stopped():
                        if self.__messageSrv:
                            del self.__messageSrv

# Path: FileHandling.py
# def getCPUTimes(workDir):
#     """ Extract and add up the total CPU times from the job report """
#     # Note: this is used with Event Service jobs
# 
#     # Input:  workDir (location of jobReport.json)
#     # Output: cpuCU (unit), totalCPUTime, conversionFactor
# 
#     totalCPUTime = 0L
# 
#     jobReport_dictionary = getJobReport(workDir)
#     if jobReport_dictionary != {}:
#         if jobReport_dictionary.has_key('resource'):
#             resource_dictionary = jobReport_dictionary['resource']
#             if resource_dictionary.has_key('executor'):
#                 executor_dictionary = resource_dictionary['executor']
#                 for format in executor_dictionary.keys(): # "RAWtoESD", ..
#                     if executor_dictionary[format].has_key('cpuTime'):
#                         try:
#                             totalCPUTime += executor_dictionary[format]['cpuTime']
#                         except:
#                             pass
#                     else:
#                         tolog("Format %s has no such key: cpuTime" % (format))
#             else:
#                 tolog("No such key: executor")
#         else:
#             tolog("No such key: resource")
# 
#     conversionFactor = 1.0
#     cpuCU = "s"
# 
#     return cpuCU, totalCPUTime, conversionFactor


# Path: HPC/EventServer/EventServerJobManager.py
import inspect
import commands
import os
import re
import signal
import sys
import time
import Queue
import multiprocessing
import subprocess
import threading
import json
import traceback
    import yampl
from pandayoda.yodacore import Logger
from FileHandling import getCPUTimes
from signal_block.signal_block import block_sig, unblock_sig

            self.__messageQ = messageQ
            self._stop = threading.Event()
            try:
                self.__messageSrv = yampl.ServerSocket(socketname, context)
            except:
                self.__log.debug("Exception: failed to start yampl server socket: %s" % traceback.format_exc())

        def send(self, message):
            try:
                self.__messageSrv.send_raw(message)
            except:
                self.__log.debug("Exception: failed to send yampl message: %s" % traceback.format_exc())

        def stop(self):
            self._stop.set()

        def stopped(self):
            return self._stop.isSet()

        def __del__(self):
            if self.__messageSrv:
                del self.__messageSrv
                self.__messageSrv = None

        def run(self):
            try:
                while True:
                    if self.stopped():
                        if self.__messageSrv:
                            del self.__messageSrv

                            self.__messageSrv = None