Skip to content

gh-135852: Remove out of tree pywin32 dependency for NTEventLogHandler#137860

Merged
serhiy-storchaka merged 29 commits intopython:mainfrom
aisk:nteventlog
Dec 31, 2025
Merged

gh-135852: Remove out of tree pywin32 dependency for NTEventLogHandler#137860
serhiy-storchaka merged 29 commits intopython:mainfrom
aisk:nteventlog

Conversation

@aisk
Copy link
Copy Markdown
Member

@aisk aisk commented Aug 16, 2025

Please note that the lpUserSid parameter in ReportEvent don't added because it needs passing a new struct from Python to it, and we don't need this parameter for the usage of implement NTEventLogHandler. If we want add it in the future, we can add it as kwargs.

Docuements for these functions:

For the NTEventLogHandler, there is a implementation detail:

The old implementation based on pywin32, if dllname is not specified, pywin32 will using a vendored dll in that package, as a log template for the NT event log system.

For the new implement in this PR, if the dllname is not specified, I decided not to register the dll. As a result, the log still can be send to the NT Event Log System, we can see it in the Event Viewer.

But the event will show some thing like this (I just use a picture from the Internet because I'm using a localized Windows which the text is Chinese but they are the same thing):

3dcfe02f31b83fb2ddbe167ee871f91278a8885c_2_571x500

And I think it's OK because we can check the Detail tab to see the original message, for develop purpose this is enough. For users with production usage, they can provide their own dlls as the message template.

{2AD0DB7D-2BDC-4C4F-ABFF-064BD3787642}

Copy link
Copy Markdown
Contributor

@sharktide sharktide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the test fails :)

@aisk
Copy link
Copy Markdown
Member Author

aisk commented Aug 18, 2025

Sorry, I forgot to check the CI result after the push.

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR @aisk. It look interesting.

Could you please show how can this be used in NTEventLogHandler? Maybe not in this PR, but in a separate PR created on top of this?

Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
@aisk aisk marked this pull request as draft September 8, 2025 15:52
@aisk aisk marked this pull request as ready for review September 9, 2025 17:27
@aisk
Copy link
Copy Markdown
Member Author

aisk commented Sep 9, 2025

Thank you for your PR @aisk. It look interesting.

Could you please show how can this be used in NTEventLogHandler? Maybe not in this PR, but in a separate PR created on top of this?

Thanks for the view! I'll create another PR based on this to try to implement the whole feature in the original issue.

@aisk aisk requested a review from vsajip as a code owner October 19, 2025 14:39
@aisk aisk changed the title gh-135852: Add NTEventLog related functions to _winapi gh-135852: Remove out of tree pywin32 dependency for NTEventLogHandler Oct 19, 2025
@aisk
Copy link
Copy Markdown
Member Author

aisk commented Oct 19, 2025

@serhiy-storchaka Hi, I found that using this in NTEventLogHandler to replace pywin32 is very simple, so I push it directly on this branch, and also added some information on the top of this issue.

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well. I have some nitpicks and questions, but mostly LGTM.

NTEventLogHandler only uses a single-string list and don't use a raw_data. Removing these features would simplify the code. But it is fine to keep them for future.

Comment thread Lib/logging/handlers.py Outdated
Comment thread Lib/logging/handlers.py Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Modules/_winapi.c Outdated
Comment thread Lib/logging/handlers.py Outdated
Comment thread Lib/test/test_winapi.py Outdated
Comment thread Lib/test/test_winapi.py
Comment thread Lib/test/test_winapi.py Outdated
Comment thread Lib/test/test_winapi.py Outdated
@aisk
Copy link
Copy Markdown
Member Author

aisk commented Oct 24, 2025

Hi, thank you for the review! I changed to just to support a single string as event log message to reduce the complexity, and now the codes are ready for review.

Comment thread Lib/test/test_winapi.py Outdated
Comment thread Lib/test/test_winapi.py Outdated
Comment thread Modules/_winapi.c Outdated
aisk and others added 5 commits October 25, 2025 00:26
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka serhiy-storchaka merged commit 3c4429f into python:main Dec 31, 2025
49 checks passed
@serhiy-storchaka
Copy link
Copy Markdown
Member

Thank you for your contribution, @aisk. 🎄

@bedevere-bot
Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Arch Linux Asan Debug 3.x (no tier) has failed when building commit 3c4429f.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/585/builds/7088) and take a look at the build logs.
  4. Check if the failure is related to this commit (3c4429f) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/585/builds/7088

Failed tests:

  • test_math
  • test_statistics
  • test_profiling

Failed subtests:

  • test_process_pool_executor_pickle - test.test_profiling.test_sampling_profiler.test_advanced.TestProcessPoolExecutorSupport.test_process_pool_executor_pickle

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.pablogsal-arch-x86_64.asan_debug/build/Lib/test/test_profiling/test_sampling_profiler/test_advanced.py", line 237, in test_process_pool_executor_pickle
    self.assertIn("Results: [2, 4, 6]", stdout)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'Results: [2, 4, 6]' not found in ''

thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
…Handler (pythonGH-137860)

Add RegisterEventSource(), DeregisterEventSource(), ReportEvent()
and a number of EVENTLOG_* constants to _winapi.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants