1 Star 0 Fork 0

v_wanglei/SynthText_Chinese_version

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
common.py 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
李嘉辉 提交于 2017-06-26 15:42 . first
import sys
import signal
from contextlib import contextmanager
class Color: #pylint: disable=W0232
GRAY=30
RED=31
GREEN=32
YELLOW=33
BLUE=34
MAGENTA=35
CYAN=36
WHITE=37
CRIMSON=38
def colorize(num, string, bold=False, highlight = False):
assert isinstance(num, int)
attr = []
if highlight: num += 10
attr.append(str(num))
if bold: attr.append('1')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
def colorprint(colorcode, text, o=sys.stdout, bold=False):
o.write(colorize(colorcode, text, bold=bold))
def warn(msg):
print colorize(Color.YELLOW, msg)
def error(msg):
print colorize(Color.RED, msg)
# http://stackoverflow.com/questions/366682/how-to-limit-execution-time-of-a-function-call-in-python
class TimeoutException(Exception): pass
@contextmanager
def time_limit(seconds):
def signal_handler(signum, frame):
raise TimeoutException, colorize(Color.RED, " *** Timed out!", highlight=True)
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(seconds)
try:
yield
finally:
signal.alarm(0)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/v_wanglei/SynthText_Chinese_version.git
git@gitee.com:v_wanglei/SynthText_Chinese_version.git
v_wanglei
SynthText_Chinese_version
SynthText_Chinese_version
master

搜索帮助