You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

algorithm-track.py 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """
  2. /**
  3. * Copyright 2020 Tianshu AI Platform. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. * =============================================================
  17. */
  18. """
  19. # coding:utf-8
  20. import threading
  21. import time
  22. import sys
  23. sys.path.append("../")
  24. import common.RedisUtil as f
  25. import common.config as config
  26. import luascript.starttaskscript as start_script
  27. import logging
  28. from entrance.executor import track
  29. logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',
  30. level=logging.DEBUG)
  31. if __name__ == '__main__':
  32. """Track algorithm entry."""
  33. jsonData = config.loadJsonData(config.configPath)
  34. redisClient = f.getRedisConnection(jsonData["ip"], jsonData["port"], jsonData["database"], jsonData["password"])
  35. logging.info('init redis client %s', redisClient)
  36. t = threading.Thread(target=track.delayKeyThread, args=(redisClient,))
  37. t.setDaemon(True)
  38. t.start()
  39. while 1:
  40. try:
  41. if config.loadJsonData(config.sign) == 0:
  42. logging.info('not to execute new task')
  43. time.sleep(1)
  44. else:
  45. logging.info('get one task')
  46. element = redisClient.eval(start_script.startTaskLua, 1, config.trackTaskQueue,
  47. config.trackStartQueue, int(time.time()))
  48. if len(element) > 0:
  49. key = element[0].decode()
  50. jsonStr = f.getByKey(redisClient, key.replace('"', ''));
  51. if track.trackProcess(jsonStr, element[0]):
  52. f.pushToQueue(redisClient, config.trackFinishQueue, key)
  53. redisClient.zrem(config.trackStartQueue, element[0])
  54. logging.info('success')
  55. else:
  56. f.pushToQueue(redisClient, config.trackFailedQueue, key)
  57. redisClient.zrem(config.trackStartQueue, element[0])
  58. logging.info('failed')
  59. else:
  60. logging.info('task queue is empty.')
  61. time.sleep(1)
  62. except Exception as e:
  63. logging.error('except:', e)
  64. time.sleep(1)

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)