enthought / enthought/mayavi

Mayavi `mlab.animate` hangs with Multiprocessing

Open
#1,153 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
316
Avg merge
7h 44m
Merged PRs (30d)
5

Description

I am doing some computation on one process and attempting to do 3d plotting on a second process. The idea is send data across a `multiprocessing.Queue` to the second process where a `mlab.points3d` object is modified using `.set`. However, I can't even get a basic animation working with `multiprocessing.Process`. Here is an MWE:

```
"""3d point animation using mayavi"""
import numpy as np
from multiprocessing import Queue, Process
from mayavi import mlab

class Plotter:

def __init__(self) -> None:
self.ball = mlab.points3d(np.array(1.), np.array(0.), np.array(0.))

@mlab.animate(delay=10)
def update(self):
t = 0.0
while True:
# Process the self.queue here
self.ball.mlab_source.set(x = np.cos(t), y = np.sin(t), z = 0)
t+=0.1

yield

def show(self, queue):
self.queue = queue
self.update(self)
mlab.show()

class Starter:

def __init__(self) -> None:
self.queue = Queue()
self.plotter = Plotter()
self.process = Process(target=self.plotter.show, args=(self.queue,), daemon=True)
self.process.start()

def submit(self, data):
self.queue.put_nowait(data)

def end(self):
self.process.terminate()
self.process.join()
self.queue.close()

if __name__ == "__main__":
# UNCOMMENT: The following works
# plotter = Plotter()
# plotter.update(plotter)
# mlab.show()

# Multiprocessing doesn't work :[
starter = Starter()
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.