()
| 137 | |
| 138 | |
| 139 | def restart() -> None: |
| 140 | # Restart this process (only safe for dev/debug) |
| 141 | executable = sys.executable |
| 142 | script_path = Path(sys.argv[0]).resolve() |
| 143 | args = sys.argv[1:] |
| 144 | main_package = sys.modules["__main__"].__package__ |
| 145 | |
| 146 | if main_package is None: |
| 147 | # Executed by filename |
| 148 | if platform.system() == "Windows": |
| 149 | if not script_path.exists() and script_path.with_suffix(".exe").exists(): |
| 150 | # quart run |
| 151 | executable = str(script_path.with_suffix(".exe")) |
| 152 | else: |
| 153 | # python run.py |
| 154 | args = [str(script_path), *args] |
| 155 | else: |
| 156 | if script_path.is_file() and os.access(script_path, os.X_OK): |
| 157 | # hypercorn run:app --reload |
| 158 | executable = str(script_path) |
| 159 | else: |
| 160 | # python run.py |
| 161 | args = [str(script_path), *args] |
| 162 | else: |
| 163 | # Executed as a module e.g. python -m run |
| 164 | module = script_path.stem |
| 165 | import_name = main_package |
| 166 | if module != "__main__": |
| 167 | import_name = f"{main_package}.{module}" |
| 168 | args[:0] = ["-m", import_name.lstrip(".")] |
| 169 | |
| 170 | os.execv(executable, [executable] + args) |
| 171 | |
| 172 | |
| 173 | async def cancel_tasks(tasks: set[asyncio.Task]) -> None: |
no outgoing calls
no test coverage detected
searching dependent graphs…