[英]Why am I getting a bad file descriptor error while calling a C function to write to log?
该函数调用C函数从Python写入日志。 它确实打印日志文本但在它之后抛出错误。 我究竟做错了什么?
def py_log_callback(msg, level):
if not string_at(msg):
return
msg = "Log entry: {}".format(string_at(msg).decode())
print(msg)
log_callback = CFUNCTYPE(None, c_char_p, c_int)(py_log_callback)
lib = CDLL(libpath)
lib.Foo(log_callback, DEBUG_LEVEL)
输出:
Log entry: <log text here>
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 234, in 'calling callback function'
File "test.py", line 36, in py_log_callback
print(msg)
OSError: [Errno 9] Bad file descriptor
我刚刚将输出保存到文本文件中,问题得到解决。
sys.stdout = open('stdout.txt', 'w')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.