commit 13ab316144e49007a58bbf14910c656ed2a5181e Author: Sven Augustin Date: Sat Feb 6 12:40:18 2021 +0000 prototype diff --git a/modman/importing.py b/modman/importing.py new file mode 100644 index 0000000..fc9e9c1 --- /dev/null +++ b/modman/importing.py @@ -0,0 +1,13 @@ +import sys +import importlib.util + + +def load_module(module_name, file_path): + spec = importlib.util.spec_from_file_location(module_name, file_path) + module = importlib.util.module_from_spec(spec) + sys.modules[module_name] = module + spec.loader.exec_module(module) + return module + + + diff --git a/modman/main.py b/modman/main.py new file mode 100755 index 0000000..ffd13f6 --- /dev/null +++ b/modman/main.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +from pathlib import Path +from time import sleep +from concurrent.futures import ThreadPoolExecutor + +from importing import load_module + + +def load_files(folder): + folder = Path(folder) + fnames = folder.glob("*.py") + fnames = sorted(fnames) + + res = {} + for fn in fnames: + print(fn, fn.stat().st_mtime) + name = fn.stem + mod = load_module(name, fn) + res[name] = mod.run + return res + + +folder = "scripts" +mods = load_files(folder) + +while True: + with ThreadPoolExecutor() as ex: + for f in mods.values(): + fut = ex.submit(f) + print(fut) + + sleep(1) + + + diff --git a/modman/scripts/test1-sleep.py b/modman/scripts/test1-sleep.py new file mode 100755 index 0000000..71539e4 --- /dev/null +++ b/modman/scripts/test1-sleep.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +from time import sleep + +def run(): + print("Test Sleep: start") + sleep(1) + print("Test Sleep: done") + + diff --git a/modman/scripts/test2-global-variable.py b/modman/scripts/test2-global-variable.py new file mode 100755 index 0000000..855c70d --- /dev/null +++ b/modman/scripts/test2-global-variable.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +N = 0 + +def run(): + global N + print("Test Global Variable:", N) + N += 1 + + diff --git a/modman/scripts/test3-global-class.py b/modman/scripts/test3-global-class.py new file mode 100644 index 0000000..db57bb4 --- /dev/null +++ b/modman/scripts/test3-global-class.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + + +class Counter: + + def __init__(self): + self.n = 0 + + def inc(self): + self.n += 1 + + def __str__(self): + return str(self.n) + + +counter = Counter() + + +def run(): + print("Test Global Class:", counter) + counter.inc() + + diff --git a/modman/scripts/test4-callable-class.py b/modman/scripts/test4-callable-class.py new file mode 100644 index 0000000..b0197cd --- /dev/null +++ b/modman/scripts/test4-callable-class.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + + +class Run: + + def __init__(self): + self.n = 0 + + def inc(self): + self.n += 1 + + def __str__(self): + return f"Test Callable Class: {self.n}" + + def __call__(self): + print(self) + self.inc() + + +run = Run() + +