<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: times new roman,new york,times,serif; font-size: 12pt; color: #000000'>Andy,<br><br>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:<br><br>    package/<br>        driver/<br>            driver.py<br>        scripts/<br>            filewithparaviewstuff.py<br>            utilities.py<br><br>The contents of each file are really simple:<br><br>    utilities.py:<br>        def hi():<br>            print "Hi there"<br><br>    filewithparaviewstuff.py:<br>        from .utilities import *<br>        from paraview.simple import *<br><br>        def my_pv():<br>            hi()<br><br>     driver.py:<br>         import sys<br>         sys.path.append('/path/to/package/')<br>         from scripts.filewithparaviewstuff import *<br><br>         my_pv()<br><br>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. <br><br>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?<br><br>Tim<br><br><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Andy Smith" <agsmith424@gmail.com><br><b>To: </b>paraview@paraview.org<br><b>Sent: </b>Tuesday, January 26, 2016 11:10:34 PM<br><b>Subject: </b>[Paraview] Call Python function with parallel reader without        pvbatch directly<br><br><div dir="ltr"><div>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.<br><br></div><div>A little background:<br></div><div>The file structure is something like this:<br><br></div><div><span style="font-family:monospace,monospace">mypythonpackage/<br></span></div><div><span style="font-family:monospace,monospace">   scripts/<br></span></div><div><span style="font-family:monospace,monospace">      my_driver_script.py<br>   mypythonpackage/<br></span></div><div><span style="font-family:monospace,monospace">      paraview/<br></span></div><div><span style="font-family:monospace,monospace">         filewithparaviewstuff.py<br></span></div><div><span style="font-family:monospace,monospace">         utilities.py<br></span></div><div><br></div><div>The driver script takes inputs and then calls a function in <span style="font-family:monospace,monospace">filewithparaviewstuff.py</span> 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:<br><br></div><div>1. Use the subprocess Python package inside the <span style="font-family:monospace,monospace">my_driver_script.py</span> to call the <span style="font-family:monospace,monospace">filewithparaviewstuff.py</span> using <span style="font-family:monospace,monospace">pvbatch</span>.<br></div><div>2. Use the subprocess Python package inside the <span style="font-family:monospace,monospace">my_driver_script.py</span> to start a <span style="font-family:monospace,monospace">pvserver</span> and then connect to this server within the function inside <span style="font-family:monospace,monospace">filewithparaviewstuff.py</span><br><br></div><div>The issue I have is the <span style="font-family:monospace,monospace">filewithparaviewstuff.py</span><span style="font-family:arial,helvetica,sans-serif"> calls some functions in the utilities.py file.  I'm trying to follow <a href="https://www.python.org/dev/peps/pep-0328/" target="_blank">PEP 328</a> and use import statements within </span><span style="font-family:arial,helvetica,sans-serif"><span style="font-family:monospace,monospace">filewithparaviewstuff.py </span>like</span><span style="font-family:monospace,monospace">:<br><br></span></div><div><span style="font-family:monospace,monospace">from .utilities import my_utility_function<br><br></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">inside the </font></span><span style="font-family:monospace,monospace">filewithparaviewstuff.py <font face="arial,helvetica,sans-serif">but this <a href="http://stackoverflow.com/questions/11536764/attempted-relative-import-in-non-package-even-with-init-py" target="_blank">causes problems</a> if I use method 1, of calling the </font></span><span style="font-family:monospace,monospace">filewithparaviewstuff.py<font face="arial,helvetica,sans-serif"> directly with </font>pvbatch<font face="arial,helvetica,sans-serif"> or if I try to make a </font>'__main__'<font face="arial,helvetica,sans-serif"> function in the </font></span><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif"><span style="font-family:monospace,monospace">filewithparaviewstuff.py</span> and call that directly with </font>pvbatch<font face="arial,helvetica,sans-serif">.<br><br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">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?<br><br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">Thanks,<br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">Andy<br></font></span></div></div>
<br>_______________________________________________<br>Powered by www.kitware.com<br><br>Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br><br>Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView<br><br>Search the list archives at: http://markmail.org/search/?q=ParaView<br><br>Follow this link to subscribe/unsubscribe:<br>http://public.kitware.com/mailman/listinfo/paraview<br></div><br></div></body></html>