Spaces:
Sleeping
Sleeping
Download logging_pool.py from HSR-DeepThink/hypolistic: direct link, hf CLI and curl.
- Browser
- Download file 965 Bytes
-
https://huggingface.co/spaces/HSR-DeepThink/hypolistic/resolve/e56aff4404e514bdf2d76ba4fc5aa9104a2b346c/logging_pool.py
- Command line
-
hf download hf://spaces/HSR-DeepThink/hypolistic@e56aff4404e514bdf2d76ba4fc5aa9104a2b346c/logging_pool.py
-
curl -L -o logging_pool.py https://huggingface.co/spaces/HSR-DeepThink/hypolistic/resolve/e56aff4404e514bdf2d76ba4fc5aa9104a2b346c/logging_pool.py
965 Bytes
| import traceback | |
| from multiprocessing.pool import Pool | |
| import multiprocessing | |
| # Shortcut to multiprocessing's logger | |
| def error(msg, *args): | |
| return multiprocessing.get_logger().error(msg, *args) | |
| class LogExceptions(object): | |
| def __init__(self, callable): | |
| self.__callable = callable | |
| def __call__(self, *args, **kwargs): | |
| try: | |
| result = self.__callable(*args, **kwargs) | |
| except Exception: | |
| # Here we add some debugging help. If multiprocessing's | |
| # debugging is on, it will arrange to log the traceback | |
| error(traceback.format_exc()) | |
| # Re-raise the original exception so the Pool worker can | |
| # clean up | |
| raise | |
| # It was fine, give a normal answer | |
| return result | |
| class LoggingPool(Pool): | |
| def apply_async(self, func, args=(), kwds={}, callback=None): | |
| return Pool.apply_async(self, LogExceptions(func), args, kwds, callback) | |