增加计时
This commit is contained in:
parent
e55c85a5ad
commit
b6d58cf9fc
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,2 +1,6 @@
|
|||||||
/venv
|
/venv
|
||||||
config.toml
|
config.toml
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import time
|
||||||
import random
|
import random
|
||||||
import asyncio
|
import asyncio
|
||||||
import traceback
|
import traceback
|
||||||
@ -127,12 +128,13 @@ async def safe_eval(code: str) -> str:
|
|||||||
code = code.replace('exit', '好坏!\n')
|
code = code.replace('exit', '好坏!\n')
|
||||||
code = code.replace('eval', '啊哈!\n')
|
code = code.replace('eval', '啊哈!\n')
|
||||||
code = code.replace('exec', '抓住!\n')
|
code = code.replace('exec', '抓住!\n')
|
||||||
|
start_time = time.time()
|
||||||
try:
|
try:
|
||||||
import os
|
import os
|
||||||
import math
|
import math
|
||||||
import random
|
|
||||||
import decimal
|
import decimal
|
||||||
global_val = {'math': math,
|
global_val = {'time': time,
|
||||||
|
'math': math,
|
||||||
'decimal': decimal,
|
'decimal': decimal,
|
||||||
'random': random,
|
'random': random,
|
||||||
'__import__': '<built-in function __import__>',
|
'__import__': '<built-in function __import__>',
|
||||||
@ -151,6 +153,7 @@ async def safe_eval(code: str) -> str:
|
|||||||
result = result[:limit]
|
result = result[:limit]
|
||||||
except:
|
except:
|
||||||
result = traceback.format_exc()
|
result = traceback.format_exc()
|
||||||
|
end_time = time.time()
|
||||||
result = result.replace(KEY, '***')
|
result = result.replace(KEY, '***')
|
||||||
result = result.replace(HOST, '***')
|
result = result.replace(HOST, '***')
|
||||||
|
|
||||||
@ -159,7 +162,7 @@ async def safe_eval(code: str) -> str:
|
|||||||
if result == '6' or result == 6:
|
if result == '6' or result == 6:
|
||||||
result = '他确实等于 6'
|
result = '他确实等于 6'
|
||||||
|
|
||||||
result = f'{code}\neval result:\n{result}'
|
result = f'{code}\neval result:\n{result}\n耗时: {end_time - start_time} s'
|
||||||
return result
|
return result
|
||||||
except:
|
except:
|
||||||
error = traceback.format_exc()
|
error = traceback.format_exc()
|
||||||
|
Loading…
Reference in New Issue
Block a user