Ich habe einige IronPython
Code, der aus einer C#
Anwendung aufgerufen wird.
Dieser Code funktionierte gut, bis ich entschied, eine Funktion zu ändern, um in einem Thread zu laufen.
Wenn numpy Funktionen in einem Python-Thread aufgerufen werden, wird eine InsufficientMemoryException
Ausnahme ausgelöst.
Ich suchte nach Lösungen, fand aber nicht. kann jemand erklären, warum es passiert und wie kann ich es beheben?IronPython werfen InsufficientMemoryException bei der Verwendung von numpy in Threads
Ich denke, dies nur geschieht, wenn ich zwei Threads, die numpy
verwende ich Code wie folgt auszuführen:
C#:
_python.functionA(); # _python was created with "Python.CreateEngine()"
_python.functionA(); # twice on purpose
Python:
my_python_script .py
import threading
import time
import numpy
def blah():
print numpy.array([100,100,0])
def functionA():
t = threading.Timer(0,blah)
t.start()
time.sleep(2)
Und ich habe diese Ausnahme:
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\Program Files\IronPython 2.7.1\Lib\threading.py", line 552, in _Thread__bootstrap_inner
self.run()
File "c:\Program Files\IronPython 2.7.1\Lib\threading.py", line 756, in run
self.function(*self.args, **self.kwargs)
File "C:\workspace\my_python_script.py", line 113, in blah
print numpy.array([100,100,0])
MemoryError: Exception of type 'System.InsufficientMemoryException' was thrown.
Dank
UPDATE 13/07/14
Ich erhalte diese Ausnahme, auch wenn ich nur ein Thread laufen und über IronPython-Interpreter, ohne die C#:
C:\>"c:\Program Files\IronPython 2.7.1\ipy.exe"
IronPython 2.7.1 (2.7.0.40) on .NET 4.0.30319.18063
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile(r"c:\workspace\my_python_script.py")
>>> functionA()
>>> Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\Program Files\IronPython 2.7.1\Lib\threading.py", line 552, in _Thread__bootstrap_inner
self.run()
File "c:\Program Files\IronPython 2.7.1\Lib\threading.py", line 756, in run
self.function(*self.args, **self.kwargs)
File "c:\workspace\my_python_script.py", line 6, in blah
print numpy.array([100,100,0])
MemoryError: Exception of type 'System.InsufficientMemoryException' was thrown.
Wie viele Prozessoren haben Sie? – gobrewers14
Ich bin mir nicht sicher, jetzt auf meinem Arbeitscomputer. Aber ich glaube, es ist mindestens Dual, vielleicht Quad. Ist es wichtig wie genau? – Elisha
Sie könnten lesen [this] (http://support.microsoft.com/kb/974065) und [dies] (http://msdn.microsoft.com/en-us/library/at1stbec.aspx) und sehen, ob Das behebt Ihr Problem. – gobrewers14