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: sjoelund.se
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 sjoelund.se 9 years ago.
Typed parsing grammar
tmp.file (236.4 KB) - added by sjoelund.se 9 years ago.
File causing memory issues for pyparsing

Download all attachments as: .zip

Change History (10)

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

comment:2 Changed 9 years ago by alash325

  • Owner changed from alash325 to sjoelund.se
  • Status changed from new to assigned

comment:3 Changed 9 years ago by sjoelund.se

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 Changed 9 years ago by sjoelund.se

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

comment:5 Changed 9 years ago by sjoelund.se

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 Changed 9 years ago by Christoph <buchner@…>

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

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

import mpl _after_ OMPython?

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

comment:8 Changed 9 years ago by sjoelund.se

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.

Changed 9 years ago by sjoelund.se

Typed parsing grammar

Changed 9 years ago by sjoelund.se

File causing memory issues for pyparsing

Note: See TracTickets for help on using tickets.