1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- # -*- coding: utf-8 -*-
- from .__load__ import *
- from gevent import monkey; monkey.patch_socket()
- import gevent
- class Loader(object):
- # 获取
- def get(self, obj='', module='', **param):
- if 'sync' in param and param['sync']:
- return Demeter.service(obj, module).get(**param)
- else:
- param['sync'] = False
- id = Demeter.service(obj, module).get(**param)
- redis = Demeter.redis()
- config = Demeter.config['redis']
- content = obj + '|' + module + '|' + str(id)
- redis.rpush(config['name'], content)
- return id
- # 启动任务
- def start(self):
- gevent.joinall([
- gevent.spawn(self.run),
- ])
- # 定时运行异步任务
- def run(self):
- timeSleep = 1
- redis = Demeter.redis()
- config = Demeter.config['redis']
- i = 0
- while 1:
- content = redis.lpop(config['name'])
- if content:
- print(content)
- command = self.command(content.decode('utf-8'))
- Shell.popen(command, False, False)
- i = i+1
- if i >= 10:
- gevent.sleep(timeSleep)
- i = 0
- def command(self, content):
- temp = content.split('|')
- python_path = sys.executable
- loader_path = os.path.join(File.path(), 'loader.py') # 生成系统规范路径
- return f'"{python_path}" "{loader_path}" -o {temp[0]} -m {temp[1]} -i {temp[2]}'
|