I want to get printed response of sync function. for that am using,
StringIO
.
import sys
from io import StringIO
def sample():
print('started to fetch log!')
print('response:body')
print('status:200')
def get_log():
sys.stdout = StringIO()
sample()
log = sys.stdout.getvalue()
sys.stdout = sys.__stdout__
return log
# in sync call,
out = get_log()
print(out)
started to fetch log!
response:body
status:200
but in async call, am unable to get those,
created async wrapper for this sync function.
async def get():
return asyncio.run(get_log())
return None. asyncio never running async function in synchronous. without running synchronous way, am unable to get print
response.
Note: I need async wrapper to coupe with existing logics.
2