question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to preload modules when workers start

See original GitHub issue

Describe your feature request

In any reasonably large project you would face an issue of circular imports. This is often handled by having a pre-defined entry point - a module that always loads first, bootstrapping the rest of the application. For instance, in web applications that would be the module holding WSGI / ASGI app. You can easily get a circular import error if the first module you attempt to import is some other random module, and not the intended one.

This is exactly what happens within Ray workers. E.g. when I start an Actor worker and it tries to unpickle the actor class, the first module it attempts to load is the module where actor is defined - leading to circular import errors as described above.

Just in case, I’m aware of _code_search_path parameter of ray.init, but that doesn’t help. All my modules are already on PATH, the only thing that’s wrong is the order in which they get imported in a Ray worker.

There should be an option to provide a list of modules, that would be imported in a given order in each worker before any other user code is run. That would allow users to ensure correct module loading order - e.g. in my case I would specify the WSGI entry point as the module to preload.

For reference, exact same functionality exists (and is widely used) in all other distributed computing libraries, e.g.:

  • Dask has preload option:

    A module or Python file passed as a --preload value is guaranteed to be imported before establishing any connection.

  • Celery has imports option:

    A sequence of modules to import when the worker starts. The modules will be imported in the original order.

I’m a bit surprised I can’t seem to find any reference to this functionality in Ray - not even within issues/discussions. It would expect the absence of that option to cause a fair amount of headache to many reasonably large projects.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nikunjgitcommented, Jul 21, 2021

Any updates here?

0reactions
wwoodscommented, Mar 30, 2022

You can put any code you want in a module that gets imported, so a static list of modules still covers this I would have thought. That is unless you want to pass some parameters to it.

Fair point. Parameters are involved, though realistically that might just be bad code hygiene.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Threading the web with module workers - web.dev
One substantial performance improvement that comes with module workers is the ability to preload workers and their dependencies.
Read more >
javascript - What happen when a script is loaded as "preload ...
Preloaded modules can also be used by both the main thread and module workers. This is useful for modules that are imported in...
Read more >
Preparing to preload modules... - NI Community
I'm having a problem with TestStand Operator Interface deployment. A message "Preparing to preload modules...." normally hung when I'm ...
Read more >
"Pre load" Powershell module - Microsoft Community Hub
My new Powershell module did have a load time of several seconds. Using this in a production environment is not an option with...
Read more >
Preload: What Is It Good For? - Smashing Magazine
Preload (spec) is a new web standard aimed at improving performance and providing more granular loading control to web developers.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found