OpenTrading / OTMql4Py

Open Trading Metatrader 4 Python Integration
GNU Lesser General Public License v3.0
104 stars 49 forks source link

iPyEvalInt("os.getpid()") cause MT4 hang #10

Open kenykau opened 7 years ago

kenykau commented 7 years ago

In OTPyTestNullEA.mq4

int OnInit(){
    ...
    ...
    iRetval = iPyEvalInt("os.getpid()"); //cause mt4 hang
}

Log file: 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] vPyInit - Opened d:\MT4\MQL4\Python\OTMql427../../Logs/_test_PyTestNullEA.txt d:\MT4\MQL4\Python\OTMql427../../Logs/_test_PyTestNullEA.txt vPyInit - Thread MainThread number 1556 Exception KeyError: KeyError(3528,) in <module 'threading' from 'C:\Python27\Lib\threading.pyc'> ignored

Work around by not a good solution:

//iRetval = iPyEvalInt("os.getpid()");   
//replace as
iRetval = uPySafeEval("os.getpid()");

Essential information for reporting Issues:

mich000r commented 7 years ago

I'm facing the same issue. After execution of OTPyTestNullEA.mq4 my log shows:

2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] vPyInit - Opened C:..\MetaQuotes\Terminal..\MQL4\Python\OTMql427../../Logs/_test_PyTestNullEA.txt C:..\MetaQuotes\Terminal..\Python\OTMql427../../Logs/_test_PyTestNullEA.txt vPyInit - Thread MainThread number 4876 ERROR:root:5584 - 4876 - <_MainThread(MainThread, stopped 4876) Traceback (most recent call last): File "C:\Program Files (x86)\Python27\Lib\threading.py", line 1104, in _exitfunc self._Threaddelete() File "C:\Program Files (x86)\Python27\Lib\threading.py", line 894, in delete del _active[_get_ident()] KeyError: 5584

After enhancing exception handling in threading.py it seems to me that the _get_ident() returns the wrong ThreadId. The MainThread id is 4876. The function at this point returns 5584. Refer to stackoverflow this issue could be triggered by monkey pathing.