Andy, 

I think I've made a mock up of what you are trying to do and may have gotten it 
to run correctly, if I understood your problem accurately. I have a structure 
like: 

package/ 
driver/ 
driver.py 
scripts/ 
filewithparaviewstuff.py 
utilities.py 

The contents of each file are really simple: 

utilities.py: 
def hi(): 
print "Hi there" 

filewithparaviewstuff.py: 
from .utilities import * 
from paraview.simple import * 

def my_pv(): 
hi() 

driver.py: 
import sys 
sys.path.append('/path/to/package/') 
from scripts.filewithparaviewstuff import * 

my_pv() 

>From here, I can do a `pvbatch driver.py` and it prints the "Hi there" string 
>as expected. I can also run it on 12 processors and get the expected 12 "Hi 
>there" strings, so it seems to work in parallel also. 

Does that help clear up the relationship between the files? Or did I 
misunderstand something and my simple example doesn't replicate the system 
properly? 

Tim 

----- Original Message -----

From: "Andy Smith" <agsmith...@gmail.com> 
To: paraview@paraview.org 
Sent: Tuesday, January 26, 2016 11:10:34 PM 
Subject: [Paraview] Call Python function with parallel reader without pvbatch 
directly 



I'd like to use a driver Python script to call a Python function within a 
module that uses ParaView to read a file in parallel and I was wondering the 
best way to go about this. 


A little background: 

The file structure is something like this: 


mypythonpackage/ 

scripts/ 

my_driver_script.py 
mypythonpackage/ 

paraview/ 

filewithparaviewstuff.py 

utilities.py 



The driver script takes inputs and then calls a function in 
filewithparaviewstuff.py that uses ParaView to load a large data file and do 
some data analysis. I need to load the dataset in parallel since it is quite 
large. To get around this in the past I've used two different methods: 


1. Use the subprocess Python package inside the my_driver_script.py to call the 
filewithparaviewstuff.py using pvbatch . 

2. Use the subprocess Python package inside the my_driver_script.py to start a 
pvserver and then connect to this server within the function inside 
filewithparaviewstuff.py 


The issue I have is the filewithparaviewstuff.py calls some functions in the 
utilities.py file. I'm trying to follow PEP 328 and use import statements 
within filewithparaviewstuff.py like : 


from .utilities import my_utility_function 


inside the filewithparaviewstuff.py but this causes problems if I use method 1, 
of calling the filewithparaviewstuff.py directly with pvbatch or if I try to 
make a '__main__' function in the filewithparaviewstuff.py and call that 
directly with pvbatch . 


Am I doing something fundamentally wrong or has anyone encountered this 
situation and come up with a more elegant solution? If not, should I just keep 
going with my option 2? 


Thanks, 

Andy 

_______________________________________________ 
Powered by www.kitware.com 

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html 

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView 

Search the list archives at: http://markmail.org/search/?q=ParaView 

Follow this link to subscribe/unsubscribe: 
http://public.kitware.com/mailman/listinfo/paraview 

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview

Reply via email to