diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-26 21:52:16 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-26 21:52:16 +0800 |
| commit | 2845da8fcbf4c6024e5c8264aab04c00c5bf26a8 (patch) | |
| tree | f5fafe60b234b1150ab171c4d429f6b997c98104 | |
| parent | 2434214fdc0af29a029250f5b38d3f8a6dc3a279 (diff) | |
sync littleblack111/stdlib
| -rwxr-xr-x | stdlib.py | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -222,6 +222,24 @@ def bgexec(func, arg=False, stop=False): else: t = Thread(target=func).start() + +# to give a absolutly perfect path to the location of a file or self(directory) +def rpath(file: str=None) -> str: + from os import path + if file: + if path.islink(file): + from os import readlink + file = readlink(file) + return f'{path.dirname(path.abspath(__file__))}/{file}' + else: + return path.dirname(path.abspath(__file__)) + +# run another python file(utils) +def runutil(file: str, *arg) -> any: + from sys import executable + from os import execv + execv(executable, ['python3', f'{rpath()}/{file}'] + list(arg)) + # TODO: fix this "TypeError: Please input @sig as a int(signal number, like 15) or str(signal name, like SIGTERM", tried signal.SIGINT, or str(signal name, like SIGTERM) # catch & handle signals def sigcatch(sig, error=None, sysexit=False, handler=None): |
