Author vladexl
Recipients eric.smith, vladexl
Date 2021-11-24.07:39:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1637739577.57.0.817408510988.issue45879@roundup.psfhosted.org>
In-reply-to
Content
Sorry i can't provide simple example, but will describe steps. And also i found reason of such behavior.
It was a function from pythonwin: PyWinObject_FromHANDLE.  When i removed it from code - issue gone.

So, in order to start 2 python scripts simultaneously:
1. 2 interpreters was created (Py_NewInterpreter)
2. 2 windows threads started and 2 python scripts inside (PyRun_AnyFileExFlags(hFile, filePath, true, nullptr);
3. Python scripts like this:  (i started additional thread inside python script, it's necessary)
@entry
def main():
	import time
	i = 100
	while i < 103 :
		print("iter {0} ".format(i))
		time.sleep(1)
		i = i +1
def entry(function):	
	def entry_decorator():
		import threading
		thread = threading.Thread(target=_threadmain, args=(function,))
		thread.start()
	return entry_decorator
def _threadmain(function):
	# call entry point from primary script
	function()
        myevent = __mymodule.GetStopEvent()
	while True:
                rc = win32event.MsgWaitForMultipleObjects((myevent,), 1, 1000, win32event.QS_ALLINPUT);
		if rc == win32event.WAIT_OBJECT_0:
			break
		pythoncom.PumpWaitingMessages()
	pythoncom.CoUninitialize() 
4. GetStopEvent like this:
PyObject* GetStopEvent(PyObject *self, PyObject *args)
{
     HANDLE hEvent = CreateEvent(...);
     return PyWinObject_FromHANDLE(hEvent);
}
5. Exception appears after starting/stopping(firing event) 3..4 times. It works fine in case of single starting.
History
Date User Action Args
2021-11-24 07:39:37vladexlsetrecipients: + vladexl, eric.smith
2021-11-24 07:39:37vladexlsetmessageid: <1637739577.57.0.817408510988.issue45879@roundup.psfhosted.org>
2021-11-24 07:39:37vladexllinkissue45879 messages
2021-11-24 07:39:37vladexlcreate