-
Notifications
You must be signed in to change notification settings - Fork 480
Expand file tree
/
Copy pathTestPythonParaViewWebiPythonMPI.py
More file actions
72 lines (62 loc) · 2.5 KB
/
TestPythonParaViewWebiPythonMPI.py
File metadata and controls
72 lines (62 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#/usr/bin/env python
# Global python import
import exceptions, traceback, logging, random, sys, threading, time, os
# Update python path to have ParaView libs
build_path='/Volumes/SebKitSSD/Kitware/code/ParaView/build-ninja'
sys.path.append('%s/lib'%build_path)
sys.path.append('%s/lib/site-packages'%build_path)
# ParaView import
from vtk.web import server
from paraview.vtk import *
from paraview.web import wamp as pv_wamp
from paraview.web import ipython as pv_ipython
from vtk.vtkCommonCore import *
from vtk.vtkCommonDataModel import *
from vtk.vtkCommonExecutionModel import *
from vtk.vtkFiltersSources import *
from vtk.vtkParallelCore import *
from vtk.vtkParaViewWebCore import *
from vtk.vtkPVClientServerCoreCore import *
from vtk.vtkPVServerManagerApplication import *
from vtk.vtkPVServerManagerCore import *
from vtk.vtkPVVTKExtensionsCore import *
from vtk import *
#------------------------------------------------------------------------------
# Start server
#------------------------------------------------------------------------------
paraviewHelper = pv_ipython.ParaViewIPython()
webArguments = pv_ipython.WebArguments('%s/www' % build_path)
sphere = None
def start():
paraviewHelper.Initialize(os.path.join(os.getcwd(), 'Testing', 'Temporary', 'mpi-python'))
pv_ipython.IPythonProtocol.updateArguments(webArguments)
paraviewHelper.SetWebProtocol(pv_ipython.IPythonProtocol, webArguments)
return paraviewHelper.Start()
def start_thread():
# Register some data at startup
global sphere
position = [random.random() * 2, random.random() * 2, random.random() * 2]
sphere = vtkSphereSource()
sphere.SetCenter(position)
sphere.Update()
pv_ipython.IPythonProtocol.RegisterDataSet('iPython-demo', sphere.GetOutput())
# Start root+satelites
thread = threading.Thread(target=start)
print "Starting thread"
thread.start()
for i in range(20):
print "Working... %ds" % (i*5)
position = [random.random() * 2, random.random() * 2, random.random() * 2]
print position
sphere.SetCenter(position)
sphere.Update()
pv_ipython.IPythonProtocol.RegisterDataSet('iPython-demo', sphere.GetOutput())
time.sleep(5)
pv_ipython.IPythonProtocol.ActivateDataSet('iPython-demo')
thread.join()
print "Done"
#------------------------------------------------------------------------------
# Main
#------------------------------------------------------------------------------
if __name__ == "__main__":
start_thread()