Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Known issue] RuntimeError when custom python LogWriter is dropped. #448

Open
BigBoot opened this issue Mar 26, 2024 · 0 comments
Open

[Known issue] RuntimeError when custom python LogWriter is dropped. #448

BigBoot opened this issue Mar 26, 2024 · 0 comments
Labels
bug no-stale Issue will not be marked as stale

Comments

@BigBoot
Copy link
Contributor

BigBoot commented Mar 26, 2024

Describe the bug

If a custom python LogWriter object is set and dropped, the next logging output will lead to a RuntimeError: Tried to call pure virtual function "ifm3d::LogWriter::write" error. To ensure the logging works as expected the custom python LogWriter instance needs to be kept alive for the whole Lifetime of the program.

To Reproduce

# Define a custom LogWriter
class MyLogWriter(LogWriter):
    def write(self, entry: LogEntry) -> None:
        print("Logging from python: ", LogFormatterText.format(entry))

if __name__ == "__main__":
    # The python instance will be dropped after the set_writer method returns leading to a RuntimeError on the next logging call
    Logger.set_writer(MyLogWriter())

Workaround

Ensure the python LogWriter instance stays valid for the whole runtime of the application:

# Define a custom LogWriter
class MyLogWriter(LogWriter):
    def write(self, entry: LogEntry) -> None:
        print("Logging from python: ", LogFormatterText.format(entry))

# Create a global MyLogWriter instance
MY_LOGGER = MyLogWriter()

if __name__ == "__main__":
  # Assign the LogWriter instance
  Logger.set_writer(MY_LOGGER)
@BigBoot BigBoot added bug no-stale Issue will not be marked as stale labels Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug no-stale Issue will not be marked as stale
Projects
None yet
Development

No branches or pull requests

1 participant