I am creating a Python API around the black box of the .NET DLL using Python.NET. The DLL only performs network operations. The DLL requires me to start the Windows message forwarding cycle, otherwise network operations get stuck after a while. I am starting a Windows message loop using System.Windows.Forms.Application.Run()in the main thread. This works just fine for getting data. My program starts to behave strangely, although when I start making calls from another Python thread in the DLL. I think this is due to stream processing, because the problems are very blurry - network events disappear or arrive very late. As far as I know, Python and C # are thread safe, but maybe due to the many wrapping layers, something is going wrong.
So, I have a couple of questions:
Is it a good idea to make DLL calls from multiple Python Arabs? Or does it depend on the internal components of the DLL? I thought that from a DLL point of view, Python threads are treated as a single agent due to the GIL.
Does every Python thread using this DLL require a message?
It is probably recommended that you maintain all DLL interactions in a single thread. I am having difficulty with this since I control the message pump circuit in the main stream. My naive approach would be to put new outgoing network messages generated in my workflow into a Python queue, create a custom message pump circuit in the main thread that processes Windows events, but also controls my queue, and if there is a message, a call in the dll. But this is all quite awkward and works a lot for such a simple task. Is this the right approach?
Is there any other way to put a function in the main Windows event loop that monitors the previously described queue and takes action? Or should I dive into the .NET specification and start using .NET events or dispatchers?