Opened 9 years ago

Last modified 9 years ago

#3764 assigned defect

OMCSession.sendExpression uses up all available memory when pyplot is imported

Reported by: christopher.schoelzel@… Owned by: Martin Sjölund
Priority: normal Milestone: Future
Component: OMPython Version: v1.9.4-v1.9.x
Keywords: Cc:

Description

I wanted to create a testing script for my modelica models using OMPython when I discovered something very strange: The code example below behaves different depending on whether the pyplot module is imported or not. If the module is imported, the parser call in OMCSession.sendExpression will use up all available memory (at least up to 8 GB). If the module is not imported or if OMCSession.execute is used instead of OMCSession.sendExpression, the memory consumption stays below 100 MB.

# OS: Windows 7
# OMPython version: 2.0.7
# OpenModelica version: 1.9.4
# python version: 2.7.11
# output of 'pip freeze':
#   cycler==0.10.0
#   matplotlib==1.5.1
#   numpy==1.10.4
#   OMPython==2.0.7
#   pyparsing==2.1.0
#   python-dateutil==2.5.0
#   pytz==2015.7
#   six==1.10.0

import OMPython
# comment out the following line and the code below will work for both 'execute' and 'sendExpression'
import matplotlib.pyplot as plt

s = OMPython.OMCSession()
print s.sendExpression("loadModel(Modelica)")
print s.sendExpression("simulate(Modelica.Electrical.Machines.Examples.DCMachines.DCPM_Start,stopTime=100,numberOfIntervals=100000)")
# execute: normal behavior
data = s.execute("readSimulationResult(currentSimulationResult,{time, ground.p.v, ground.p.i})")
# sendExpression: consumes all available RAM
# data = s.sendExpression("readSimulationResult(currentSimulationResult,{time, ground.p.v, ground.p.i})")
del s

Attachments (2)

c.py (2.0 KB ) - added by Martin Sjölund 9 years ago.
Typed parsing grammar
tmp.file (236.4 KB ) - added by Martin Sjölund 9 years ago.
File causing memory issues for pyparsing

Download all attachments as: .zip

Change History (10)

comment:1 by Christoph <buchner@…>, 9 years ago

comment:2 by Alachew Mengist, 9 years ago

Owner: changed from Alachew Mengist to Martin Sjölund
Status: newassigned

comment:3 by Martin Sjölund, 9 years ago

I guess this is to be expected. The simulation result is huge and is sent as a text-string that a parser needs to read.

comment:4 by Martin Sjölund, 9 years ago

Also, https://github.com/OpenModelica/OMPython/issues/3 is unrelated. They are supposed to give different results.

comment:5 by Martin Sjölund, 9 years ago

It's weird in the sense that this only occurs if matplotlib and pyparsing are used together. I don't have time to look into any specifics, but a reduced test shows that matplotlib severly increases the memory consumption of pyparsing.
Note that matplotlib also uses pyparsing, so it is possible pyparsing has some internal state that is not thread-safe and thus not advisable to use together with OMPython.

comment:6 by Christoph <buchner@…>, 9 years ago

Does this also occur if you import mpl _after_ OMPython? If not, it could be some import order thing maybe?

comment:7 by Christoph <buchner@…>, 9 years ago

import mpl _after_ OMPython?

sorry, the other way round of course. :-P

comment:8 by Martin Sjölund, 9 years ago

Yes, the order does not matter. And I checked the threading module as well (seems to be only 1 thread). I also checked with Python3 :) It would be good if PyParsing could expose a lock or something in order to make it possible for two modules to use it... Perhaps it does...

I'll attach a small example+file that can be tested on pyparsing.

by Martin Sjölund, 9 years ago

Attachment: c.py added

Typed parsing grammar

by Martin Sjölund, 9 years ago

Attachment: tmp.file added

File causing memory issues for pyparsing

Note: See TracTickets for help on using tickets.