-
Notifications
You must be signed in to change notification settings - Fork 699
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
ctypes pickling error #342
Comments
This app is multithreaded and multiprocessed using the stdlib threading and multiprocessing modules and PyQt5's QThread class. So, using 'enqueue' is kind of forced here 😕 |
Hello @JulianOrteil. Thanks for the extensive bug report! Basically, when As you noticed, it seems the raised Actually, Loguru tries to catch possible errors during the serialization procedure of exceptions: Lines 66 to 72 in 93f1990
However, what I didn't know is that import ctypes
import pickle
pickle.dumps(lambda: None)
# _pickle.PicklingError: Can't pickle <function <lambda> at 0x7f33528ec0d0>: attribute lookup <lambda> on __main__ failed
pickle.dumps(ctypes.c_void_p(2735452554832))
# ValueError: ctypes objects containing pointers cannot be pickled I will probably change the implementation so it catch exception more generally instead of restricting it to In the meantime, I see two possible workarounds. If you know for sure where the try:
tensorrt.do_something()
except InferenceServerException:
type, _, tb = sys.exc_info()
logger.opt(exception=(type, None, tb)).error("An error occurred") Otherwise, you can do this from within your if record["exception"] is not None:
record["extra"]["stack"] = stackprinter.format(record["exception"])
format_ += "<red><bold>{extra[stack]}</bold></red>\n"
if record["exception"].type is InferenceServerException:
record["exception"] = record["exception"]._replace(value=None) |
Excellent. Thank you for the prompt response. I'll implement your suggestion and leave this bug report open if you wish to link a pull request to it. Jules |
Update: Proposed solution 1:
This produces a Proposed solution 2:
This produces an
I was able to get a work around going, but I just wanted to alert you and anyone else looking at this issue to errors encountered in the proposed solutions. My solution:
|
@JulianOrteil Yeah, sorry. I realized there will be an error with the second snippet I provided because I was thinking the Thanks for updating this ticket with an usable workaround! 😄 |
@Delgan Anytime! I also thought I would bring another workaround to this issue as well. Per the docs, Code:
|
Wow, I never noticed these methods existed nor that they were part of the documentation. O.o Again, that a great workaround. Thanks for sharing it! |
Hello. Is this error fixed at latest version 0.6.0? |
@holyachon @JulianOrteil This issue is not yet fixed but I'll handle it soon. |
Any progress on that? |
I'm closing this ticket because this has been fixed by #905 and should no longer be a problem with the next release. 👍 |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [loguru](https://togithub.com/Delgan/loguru) ([changelog](https://togithub.com/Delgan/loguru/blob/master/CHANGELOG.rst)) | `==0.7.0` -> `==0.7.2` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/loguru/0.7.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/loguru/0.7.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/loguru/0.7.0/0.7.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/loguru/0.7.0/0.7.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>Delgan/loguru (loguru)</summary> ### [`v0.7.2`](https://togithub.com/Delgan/loguru/blob/HEAD/CHANGELOG.rst#072-2023-09-11) [Compare Source](https://togithub.com/Delgan/loguru/compare/0.7.1...0.7.2) \===================== - Add support for formatting of `ExceptionGroup` errors (`#​805 <https://github.com/Delgan/loguru/issues/805>`\_). - Fix possible `RuntimeError` when using `multiprocessing.set_start_method()` after importing the `logger` (`#​974 <https://github.com/Delgan/loguru/issues/974>`\_) - Fix formatting of possible `__notes__` attached to an `Exception` (`#​980 <https://github.com/Delgan/loguru/issues/980>`\_). ### [`v0.7.1`](https://togithub.com/Delgan/loguru/blob/HEAD/CHANGELOG.rst#071-2023-09-04) [Compare Source](https://togithub.com/Delgan/loguru/compare/0.7.0...0.7.1) \===================== - Add a new `context` optional argument to `logger.add()` specifying `multiprocessing` context (like `"spawn"` or `"fork"`) to be used internally instead of the default one (`#​851 <https://github.com/Delgan/loguru/issues/851>`\_). - Add support for true colors on Windows using ANSI/VT console when available (`#​934 <https://github.com/Delgan/loguru/issues/934>`*, thanks `@tunaflsh <https://github.com/tunaflsh>`*). - Fix possible deadlock when calling `logger.complete()` with concurrent logging of an asynchronous sink (`#​906 <https://github.com/Delgan/loguru/issues/906>`\_). - Fix file possibly rotating too early or too late when re-starting an application around midnight (`#​894 <https://github.com/Delgan/loguru/issues/894>`\_). - Fix inverted `"<hide>"` and `"<strike>"` color tags (`#​943 <https://github.com/Delgan/loguru/pull/943>`*, thanks `@tunaflsh <https://github.com/tunaflsh>`*). - Fix possible untraceable errors raised when logging non-unpicklable `Exception` instances while using `enqueue=True` (`#​329 <https://github.com/Delgan/loguru/issues/329>`\_). - Fix possible errors raised when logging non-picklable `Exception` instances while using `enqueue=True` (`#​342 <https://github.com/Delgan/loguru/issues/342>`*, thanks `@ncoudene <https://github.com/ncoudene>`*). - Fix missing seconds and microseconds when formatting timezone offset that requires such accuracy (`#​961 <https://github.com/Delgan/loguru/issues/961>`\_). - Raise `ValueError` if an attempt to use nanosecond precision for time formatting is detected (`#​855 <https://github.com/Delgan/loguru/issues/855>`\_). </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/dqx-translation-project/dqxclarity). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjMiLCJ1cGRhdGVkSW5WZXIiOiIzNy44LjEiLCJ0YXJnZXRCcmFuY2giOiJtYWluIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Good day, Delgan.
I have an error I am encountering in the handlers of loguru. This error is being raised when I use "logger.exception(msg)" in the except block of a try statement.
Some context:
I'm developing an application to interface with NVIDIA's AI Triton server. The server's client-side python bindings are written in both C/C++ and Python. I'm mentioning this because I am developing on Windows, and replicating this issue is fairly hard due to specifics in the environment for the Triton server. I can give you the files and procedures to set up an environment like mine for this if you'd like, but I'll leave that up to you.
The error:
Stacktrace:
Code throwing the issue:
The exception being raised does have calls to dll's in it, so that could possibly be the root cause? Again, it is difficult to reproduce this error because of the environment.
Exception data as returned by 'sys.exc_info()':
Logger setup code:
Please let me know if there is anything more I can provide.
Jules
The text was updated successfully, but these errors were encountered: