mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-19 17:56:43 +00:00
Add customstderr
This commit is contained in:
parent
765f6f59b7
commit
ae59522b27
@ -1,9 +1,8 @@
|
|||||||
|
import atexit
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
|
|
||||||
import atexit
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
import siphash
|
import siphash
|
||||||
@ -23,7 +22,9 @@ def retry(attempts, callback=None, retry_sleep=0):
|
|||||||
callback(e)
|
callback(e)
|
||||||
retries -= 1
|
retries -= 1
|
||||||
sleep(retry_sleep)
|
sleep(retry_sleep)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
return decorate
|
return decorate
|
||||||
|
|
||||||
|
|
||||||
@ -105,4 +106,20 @@ class CustomStdOut:
|
|||||||
self.fp.close()
|
self.fp.close()
|
||||||
|
|
||||||
|
|
||||||
|
class CustomStdErr:
|
||||||
|
original_stderr = sys.stderr
|
||||||
|
|
||||||
|
def __init__(self, fname):
|
||||||
|
self.fname = fname
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.fp = open(self.fname, "w")
|
||||||
|
sys.stderr = self.fp
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
sys.stdout = CustomStdErr.original_stderr
|
||||||
|
self.fp.close()
|
||||||
|
|
||||||
|
|
||||||
silent_stdout = CustomStdOut(os.devnull)
|
silent_stdout = CustomStdOut(os.devnull)
|
||||||
|
silent_stderr = CustomStdErr(os.devnull)
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.39",
|
version="1.40",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user