Esempio n. 1
0
def combin_cur_dir(sub_dir):
    """组合目录
    当前执行文件的目录作为根目录, 支持多进程
    sub_dir: 当前执行文件下的子目录, 前面不带/
    return: 绝对路径
    """
    key = myredis.gen_keyname(__file__, combin_cur_dir)
    enter_file = sys.argv[0]
    root_dir = os.path.dirname(os.path.abspath(enter_file))
    if root_dir.lower().find('multisubprocess') >= 0:
        root_dir = myredis.get_obj(key)
    else:
        myredis.set_obj(key, root_dir)
    return root_dir + '/' + sub_dir
Esempio n. 2
0
def PostTask(fn, t, reset=False):
    """每隔t秒执行一次fn
    主要是防止交易接口被短期内多次调用, 造成系统异常
    fn : callback function
    t : 秒
    reset: 重置时间, 立刻执行
    """
    key = 'posttask_' + fn.func_name
    cur_t = curTime()
    if reset:
        myredis.delkey(key)
    pre_t = myredis.get_obj(key)
    if pre_t == None:
        pre_t = cur_t - datetime.timedelta(seconds=t + 1)

    if cur_t - pre_t > datetime.timedelta(seconds=t):
        fn()
        myredis.set_obj(key, cur_t)
Esempio n. 3
0
 def Run(self):
     self.pd_task.index = range(len(self.pd_task))
     print(self.pd_task)
     #保存任务表
     myredis.set_obj('multi', self.pd_task)
     cmd = sys.executable
     fname = 'MultiSubProcess_exec.py'
     cur_dir = os.path.abspath(os.path.dirname(__file__))
     cmd += ' ' + cur_dir + '/' + fname
     process = []
     for i in range(len(self.pd_task)):
         cur_cmd = cmd + ' ' + str(i)
         #print cur_cmd
         if sys.platform != 'win32':
             cur_cmd = cur_cmd.split(' ')
         p = subprocess.Popen(cur_cmd)
         process.append(p)
     for p in process:
         p.wait()
def main(args):
    #os.chdir(getMainDir())
    if len(args) > 0:
        i = int(args[0])
    else:
        i = 0
    #print('arg=',i)
    pd_task = myredis.get_obj('multi')
    if 0: pd_task = pd.DataFrame
    #print pd_task.iloc[i]
    v = tuple(pd_task.iloc[i].tolist()[1:])  #去掉task_id
    #print(v)
    v += (i, )  #加上task_id
    fname = v[0]
    #print('fname=',fname)
    AddPath(fname)
    module_name = getImportName(fname)
    s = 'import %s\n' % (module_name)
    # 获取import模块名
    #module.fn
    s += 'r=%s' % (module_name)
    s += '.%s(%s)' % (v[1:-1])
    #print(s)

    if sys.version > '3':
        from autoxd.pinyin.myexec import myexec
        r = myexec(s)
        #_locals = locals()
        #r = exec(s, globals(), _locals)
        #r = _locals['r']
    else:
        exec(s)

    #print(type(r))
    #print('result=',r)
    #保存结果
    try:
        myredis.set_obj(MultiSubProcess.getResultName(i), r)
        #print('save successful.', MultiSubProcess.getResultName(i))
    except:
        print("MultiSubProcess result save failed.")
Esempio n. 5
0
 def set(code):
     key = MyCode.g_code_name
     myredis.set_obj(key, code)
Esempio n. 6
0
def registe_root_path(dir):
    """在入口函数处调用"""
    key = enum.ROOT_PATH
    o = dir
    myredis.set_obj(key, o)