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.

Separate watch from nunjucks / 100% CPU Issues

See original GitHub issue

Hi, the code below causes nunjucks to use 100% of one CPU core. It makes no difference if i use different template contents, different contexts or the asyc api.

Nunjucks version: 1.1.0 Node Version: v0.10.31

var nunjucks = require('nunjucks');

nunjucks.renderString('my template', {});

setTimeout(function(){}, 1000*3600);

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:18 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
tyler-johnsoncommented, Nov 1, 2014

In case anyone else is looking for a temporary workaround, this is what I am using:

var nunjucks = require("nunjucks");
var chokidar = require("chokidar");

function configureNunjucks(paths, options) {
  var loader = new nunjucks.FileSystemLoader(paths, true);

  var watcher = chokidar.watch(loader.searchPaths, {
    ignoreInitial: true,
    usePolling: false,
    useFsEvents: true
  });

  watcher.on("all", function(event, fullname) {
    if (event == "change" && fullname in loader.pathsToNames) {
      loader.emit('update', loader.pathsToNames[fullname]);
    }
  });

  return new nunjucks.Environment(loader, options);
}

// to use:
var env = configureNunjucks("./views", { autoescape: true });
0reactions
jlongstercommented, Apr 30, 2015

The CPU issue looks to be fixed after upgrading to a much better version of chokidar: https://github.com/mozilla/nunjucks/pull/405

I’ve been working on separate the watcher, but I’m not entirely sure it’s a great idea anymore. Technically it’s just hard – how do I take a watcher from the user and use it? The only way to do this is to standardize an interface and force the user to load in a watcher compatible with it and install it. That’s just too much work in my opinion for a feature that should be builtin.

What I think we can do is support multiple watchers. If someone wants to make a PR to take a watcher option that specifies either chokidar or some other watcher, I would be open to it

Read more comments on GitHub >

github_iconTop Results From Across the Web

think-view-nunjucks 1.0.7 | Snyk
Learn more about think-view-nunjucks@1.0.7 vulnerabilities. think-view-nunjucks@1.0.7 has 7 known ... Issues · Dependencies. Severity. Critical. High.
Read more >
How to fix 100% CPU Utilization Bug (When no ... - YouTube
For those who want to give a little thanks, I just set up a page over at buymeacoffee as a new way to...
Read more >
100% CPU Usage and How to Fix It 🖥️ - YouTube
In this video, I will show you what to do if the CPU in your computer is at 100 % usage all the...
Read more >
High CPU Load - keystone - Google Groups
My problem is that after starting node and loading the main page (/), the CPU load of node will be almost 100% and...
Read more >
High CPU usage on Mac Sierra with 3143 - Technical Support ...
My CPU usage just keeps climbing until i have to shut down Sublime. It's been this way for a good number of prior...
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