I have embedded Python in an ASP.NET Framework API C# app using Python.NET and am attempting to use the selenium-wire library. To do this I have learned a little about the Python GIL. What I understand, is one key to embedding Python in another language is the Python engine must be initialized in the "main thread" (stack overflow answer). ASP.NET is inherently multi-threaded and Python is initialized in the Global.asax.csApplication_Start() which is ostensibly equivalent to the main() method.
Bugs:
The error below is thrown (set_wakeup_fd only works in main thread of the main interpreter) when the selenium-wire driver is initialized.
Furthermore, apparently logging handlers are incapable of getting disposed of, for some reason, as soon as the driver is finally initialized i.e. when using mylogger.removeHandler(myHandler).
A few interesting points:
I found, the error is not thrown if initializing the driver with the base selenium library.
After spamming the endpoint, which uses selenium-wire a few times, eventually the driver does initialize, and the error does not seem to reoccur for the lifetime of the Python/ASP.NET process.
Python.Runtime.PythonException
HResult=0x80131500
Message=set_wakeup_fd only works in main thread of the main interpreter
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
I have embedded Python in an ASP.NET Framework API C# app using Python.NET and am attempting to use the
selenium-wire
library. To do this I have learned a little about the Python GIL. What I understand, is one key to embedding Python in another language is the Python engine must be initialized in the "main thread" (stack overflow answer). ASP.NET is inherently multi-threaded and Python is initialized in theGlobal.asax.cs
Application_Start()
which is ostensibly equivalent to themain()
method.Bugs:
set_wakeup_fd only works in main thread of the main interpreter
) when theselenium-wire
driver is initialized.mylogger.removeHandler(myHandler)
.A few interesting points:
selenium
library.selenium-wire
a few times, eventually the driver does initialize, and the error does not seem to reoccur for the lifetime of the Python/ASP.NET process.Python doc on set_wakeup_fd() if that helps.