Why am I getting a bad file descriptor error while calling a C function to write to log?

vader9280

This function calls a C function to write to log from Python. It does print the log text but throws an error after it. What am I doing wrong?

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)

Output:

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
vader9280

I just saved the output to a text file and the problem was fixed.

sys.stdout = open('stdout.txt', 'w')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

write(): Bad file descriptor

Why am I getting an error when calling a webservice function?

Why am I getting a '.then is not function error'?

Why am I getting the 400 error (Bad request)

Why am I getting "Subscribe is not a function" error?

Why am I getting Listen Loop Bad File Descriptor errors on my machine but not anyone else's machine when specific code is enabled?

Why am I getting a "no matching function" error?

Why am I getting a compilation error in a C++ factorial function?

Why am I getting [Errno 9] Bad file descriptor on file.close() - error handling

Why am I getting a "bad file descriptor" error when writing file in rust?

Getting "Bad file descriptor" error during tar

why I am getting this error "undefined is not a function "

Why am I getting EXC_BAD_ACCESS error

How to use a file pointer of a file descriptor with multiple child processes without getting "Bad file descriptor" error in C?

Why am I getting the error "is not a function" here?

Why I am getting error while using apply map function in python to replace unwanted character in header name

why i am getting an error while calling a function?

Why am I getting error file format not reognized while compiling?

Getting No file error while calling a function in python

Why am i getting error in function addRandomNumbers?

Why am I getting this error upon calling TitleScreen instance?

Why am I getting an error when calling the `separate` function with a column?

Why am I getting a value error in excel while using the ifs function?

Why am i getting this error while trying to open json file?

Why am I getting this error?pipe is not a function

Django: Why am I getting a 400 bad request error?

Why am I getting an error in this C program?

Why am I getting a "Function is unused" error?

Vue.js- I am getting "this.cancelOrderFunction is not a function" error while calling method inside a child component