| 6 | |
| 7 | |
| 8 | class TaskHttp(TaskBase): |
| 9 | |
| 10 | def __init__(self): |
| 11 | TaskBase.__init__(self) |
| 12 | self.taskObj.taskBack.connect(self.HandlerTask) |
| 13 | |
| 14 | def AddHttpTask(self, req, callBack=None, backParam=None, cleanFlag=None): |
| 15 | self.taskId += 1 |
| 16 | info = QtHttpTask(self.taskId) |
| 17 | info.callBack = callBack |
| 18 | info.backParam = backParam |
| 19 | self.tasks[self.taskId] = info |
| 20 | if cleanFlag: |
| 21 | info.cleanFlag = cleanFlag |
| 22 | taskIds = self.flagToIds.setdefault(cleanFlag, set()) |
| 23 | taskIds.add(self.taskId) |
| 24 | |
| 25 | from server.server import Server |
| 26 | if isinstance(req, FunctionType): |
| 27 | req(self.taskId) |
| 28 | else: |
| 29 | from server.server import Server |
| 30 | Server().Send(req, backParam=self.taskId) |
| 31 | return |
| 32 | |
| 33 | def HandlerTask(self, taskId, data): |
| 34 | try: |
| 35 | info = self.tasks.get(taskId) |
| 36 | data = pickle.loads(data) |
| 37 | if not info: |
| 38 | Log.Warn("[Task] not find taskId:{}, {}".format(taskId, data)) |
| 39 | return |
| 40 | assert isinstance(info, QtHttpTask) |
| 41 | if info.cleanFlag: |
| 42 | taskIds = self.flagToIds.get(info.cleanFlag, set()) |
| 43 | taskIds.discard(info.taskId) |
| 44 | if info.callBack: |
| 45 | if info.backParam is None: |
| 46 | info.callBack(data) |
| 47 | else: |
| 48 | info.callBack(data, info.backParam) |
| 49 | del info.callBack |
| 50 | del self.tasks[taskId] |
| 51 | except Exception as es: |
| 52 | Log.Error(es) |
no outgoing calls
no test coverage detected