当前位置: 首页>>代码示例>>Python>>正文


Python JSONRequests.decode方法代码示例

本文整理汇总了Python中WMCore.Services.Requests.JSONRequests.decode方法的典型用法代码示例。如果您正苦于以下问题:Python JSONRequests.decode方法的具体用法?Python JSONRequests.decode怎么用?Python JSONRequests.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WMCore.Services.Requests.JSONRequests的用法示例。


在下文中一共展示了JSONRequests.decode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decodeJson

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import decode [as 别名]
    def decodeJson(self, result):
        """
        decodeJson

        decode the response result reveiced from the server
        """
        encoder = JSONRequests(idict={"pycurl" : True})
        return encoder.decode(result)
开发者ID:AndresTanasijczuk,项目名称:CRABServer,代码行数:10,代码来源:RESTInteractions.py

示例2: decodeJson

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import decode [as 别名]
    def decodeJson(self, result):
        """
        decodeJson

        decode the response result reveiced from the server
        """
        encoder = JSONRequests()
        return encoder.decode(result)
开发者ID:cinquo,项目名称:CRABClient,代码行数:10,代码来源:ServerInteractions.py

示例3: __init__

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import decode [as 别名]

#.........这里部分代码省略.........
            # We can't really do anything if we fail
            pass
        try:
            self.sink.close()
        except:
            # We can't do anything if we fail
            pass

        # Now close the workers by hand
        for worker in self.workers:
            try:
                worker.join()
            except Exception as ex:
                try:
                    worker.terminate()
                except Exception as ex2:
                    logging.error("Failure to join or terminate process")
                    logging.error(str(ex))
                    logging.error(str(ex2))
                    continue
        self.workers = []
        return

    def enqueue(self, work, list = False):
        """
        __enqeue__

        Assign work to the workers processes.  The work parameters must be a
        list where each item in the list can be serialized into JSON.

        If list is True, the entire list is sent as one piece of work
        """
        if len(self.workers) < 1:
            # Someone's shut down the system
            msg = "Attempting to send work after system failure and shutdown!\n"
            logging.error(msg)
            raise ProcessPoolException(msg)

        if not list:
            for w in work:
                encodedWork = self.jsonHandler.encode(w)
                self.sender.send(encodedWork)
                self.runningWork += 1
        else:
            encodedWork = self.jsonHandler.encode(work)
            self.sender.send(encodedWork)
            self.runningWork += 1

        return



    def dequeue(self, totalItems = 1):
        """
        __dequeue__

        Retrieve completed work from the slave workers.  This method will block
        until enough work has been completed.
        """
        completedWork = []

        if totalItems > self.runningWork:
            msg = "Asked to dequeue more work then is running!\n"
            msg += "Failing"
            logging.error(msg)
            raise ProcessPoolException(msg)

        while totalItems > 0:
            try:
                output = self.sink.recv()
                decode = self.jsonHandler.decode(output)
                if type(decode) == type({}) and decode.get('type', None) == 'ERROR':
                    # Then we had some kind of error
                    msg = decode.get('msg', 'Unknown Error in ProcessPool')
                    logging.error("Received Error Message from ProcessPool Slave")
                    logging.error(msg)
                    self.close()
                    raise ProcessPoolException(msg)
                completedWork.append(decode)
                self.runningWork -= 1
                totalItems -= 1
            except Exception as ex:
                msg =  "Exception while getting slave outputin ProcessPool.\n"
                msg += str(ex)
                logging.error(msg)
                break

        return completedWork


    def restart(self):
        """
        _restart_

        Delete everything and restart all pools
        """

        self.close()
        self.createSlaves()
        return
开发者ID:HassenRiahi,项目名称:WMCore,代码行数:104,代码来源:ProcessPool.py

示例4: WMInit

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import decode [as 别名]
    wmInit = WMInit()
    setupDB(config, wmInit)

    # Create JSON handler
    jsonHandler = JSONRequests()

    wmFactory = WMFactory(name = "slaveFactory", namespace = namespace)
    slaveClass = wmFactory.loadObject(classname = slaveClassName, args = config)

    logging.info("Have slave class")

    while(True):
        encodedInput = receiver.recv()

        try:
            input = jsonHandler.decode(encodedInput)
        except Exception as ex:
            logging.error("Error decoding: %s" % str(ex))
            break

        if input == "STOP":
            break

        try:
            logging.error(input)
            output = slaveClass(input)
        except Exception as ex:
            crashMessage = "Slave process crashed with exception: " + str(ex)
            crashMessage += "\nStacktrace:\n"

            stackTrace = traceback.format_tb(sys.exc_info()[2], None)
开发者ID:HassenRiahi,项目名称:WMCore,代码行数:33,代码来源:ProcessPool.py

示例5: JSONRequests

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import decode [as 别名]
if __name__ == "__main__":
    """
    __main__

    Entry point for the slave process.  The slave's classname will be passed in
    on the command line.  The database connection parameters as well as the
    name of the directory that the log files will be stored in will be passed
    in through stdin as a JSON object.
    """
    
    slaveClassName = sys.argv[1]

    jsonHandler = JSONRequests()

    encodedConfig = sys.stdin.readline()
    config = jsonHandler.decode(encodedConfig)

    encodedSlaveInit = sys.stdin.readline()
    if encodedSlaveInit != "\n":
        unicodeSlaveInit = jsonHandler.decode(encodedSlaveInit)
        slaveInit = {}
        for key in unicodeSlaveInit.keys():
            slaveInit[str(key)] = unicodeSlaveInit[key]
    else:
        slaveInit = None

    wmInit = WMInit()
    setupLogging(config["componentDir"])
    setupDB(config, wmInit)

    namespace = config.get('namespace', 'WMComponent')
开发者ID:zhiwenuil,项目名称:WMCore,代码行数:33,代码来源:ProcessPool.py


注:本文中的WMCore.Services.Requests.JSONRequests.decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。