I wrapped code that could end without using a try / except block. However, although a MemoryError is thrown, it is not caught.
I have the following code:
while True: try: self.create_indexed_vocab( vocab ) self.reset_weights() break; except MemoryError:
I get the following Traceback:
File "./make_model_tagged_wmt11.py", line 39, in <module> model.build_vocab(sentences) File "/root/CustomCompiledSoftware/gensim/gensim/models/word2vec.py", line 236, in build_vocab self.reset_weights() File "/root/CustomCompiledSoftware/gensim/gensim/models/word2vec.py", line 347, in reset_weights self.syn0 += (random.rand(len(self.vocab), self.layer1_size) - 0.5) / self.layer1_size File "mtrand.pyx", line 1044, in mtrand.RandomState.rand (numpy/random/mtrand/mtrand.c:6523) File "mtrand.pyx", line 760, in mtrand.RandomState.random_sample (numpy/random/mtrand/mtrand.c:5713) File "mtrand.pyx", line 137, in mtrand.cont0_array (numpy/random/mtrand/mtrand.c:1300) MemoryError
I am running Python 2.7.3 under Ubuntu 12.04
The line reset_weights self.syn0 is exactly the line that I expect to raise an exception (it allocates a large array). The mysterious thing is that I cannot catch a memory error and do something that will make the array size smaller.
Are there any special circumstances that make it impossible to capture a MemoryError ?
python exception-handling out-of-memory
Eponymous Nov 11 '13 at 6:09 2013-11-11 06:09
source share