-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall_anonymous_function_recursively.py
executable file
·63 lines (49 loc) · 1.87 KB
/
call_anonymous_function_recursively.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/bin/env -S /usr/bin/time /usr/bin/python3.9.5 -i
# -*- coding: utf-8 -*-
# Some other needed imports
import datetime
import dill
import gzip
import os
import pdb
import re
import sys
import traceback
import numpy as np
import pandas as pd
import multiprocessing as mp
from collections import defaultdict
from copy import deepcopy, copy
from dotmap import DotMap
from functools import reduce
from hashlib import sha256
from io import BytesIO
from memory_tempfile import MemoryTempfile
from shutil import copyfile
from pprint import pprint
from typing import List, Set, Tuple, Dict, Union, Any
from PIL import Image
CURRENT_WORKING_DIR = os.getcwd()
PATH_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
HOME_DIR = os.path.expanduser("~")
TEMP_DIR = MemoryTempfile().gettempdir()
PYTHON_PROGRAMS_DIR = os.path.join(HOME_DIR, 'git/python_programs')
# set the relative/absolute path where the utils_load_module.py file is placed!
sys.path.append(PYTHON_PROGRAMS_DIR)
from utils_load_module import load_module_dynamically
var_glob = globals()
load_module_dynamically(**dict(var_glob=var_glob, name='utils', path=os.path.join(PYTHON_PROGRAMS_DIR, "utils.py")))
load_module_dynamically(**dict(var_glob=var_glob, name='utils_multiprocessing_manager', path=os.path.join(PYTHON_PROGRAMS_DIR, "utils_multiprocessing_manager.py")))
mkdirs = utils.mkdirs
MultiprocessingManager = utils_multiprocessing_manager.MultiprocessingManager
OBJS_DIR_PATH = os.path.join(PATH_ROOT_DIR, 'objs')
mkdirs(OBJS_DIR_PATH)
PLOTS_DIR_PATH = os.path.join(PATH_ROOT_DIR, 'plots')
mkdirs(PLOTS_DIR_PATH)
def main():
d = {}
d['f'] = lambda x: (print(f'x: {x}'), d['f'](x-1))[-1] if x > 0 else print('finished!')
return d
if __name__ == '__main__':
d = main()
(lambda g: (g.__setitem__('f', lambda x: (print(f'x: {x}'), g['f'](x-1))[-1] if x > 0 else print('finished!')), g['f'](5), 'YES')[-1])({})