[vtk-developers] Speeding up `import vtk`

David Gobbi david.gobbi at gmail.com
Wed Sep 20 09:18:51 EDT 2017


Hi Ben,

I like Matt's comments on lazy-loading, it would allow us to keep backwards
compatibility while speeding up load times. Python provides a way to
override getattr() for modules:
https://stackoverflow.com/questions/2447353/getattr-on-a-module

 - David

On Tue, Sep 19, 2017 at 8:29 AM, Ben Boeckel <ben.boeckel at kitware.com>
wrote:

> [ Yes, this is a necro on this thread, but I'd like to see this happen. ]
>
> On Thu, Sep 08, 2016 at 11:14:21 -0600, David Gobbi wrote:
> > As usual, I'm a stickler for backwards compatibility and would rather go
> in
> > the other direction,
>
> How about fixing `vtk` for VTK9? I don't like having it be a separate
> module because that means we have to ship things twice and the only
> difference is the `__init__.py` file.
>
> Currently `import vtk` (the obvious thing to do) is basically like doing
> a `find_package(VTK REQUIRED)` that doesn't support `COMPONENTS`. You
> get everything built, but you also have no idea if what you need is
> actually present until you get your `AttributeError`.
>
> I'd rather see scripts explicitly request `vtk.FiltersParallel` (or
> similar) if they need it rather than just hoping it dumped the right
> things into the global namespace. If we want to keep having this
> pattern, ParaView's `paraview.simple` module provides everything needed
> to "hit the ground running" (though I don't see it as a long-term
> maintainable way to use VTK or ParaView via Python). VTK could also have
> `vtk.simple` which does this. The problem with having it at the root
> level is that it denies any advanced usage of the module which does
> request exactly what is required.
>
> With all the other big changes coming in VTK9, I think it would be a
> good time to tackle this.
>
> --Ben
>
> P.S. For those curious, this came up because we recently had one module
> have more "load commands" than the loader on macOS supports
> (vtkPVAnimation) which triggered an `ImportError`. Because `import vtk`
> loads all modules, this meant that any loading of `import vtk` was
> broken just because this one was, even tests which don't care about it
> at all.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20170920/b349ffdf/attachment.html>


More information about the vtk-developers mailing list