第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

API調(diào)用期間的NodeJs MaxListenersExceededWarning

API調(diào)用期間的NodeJs MaxListenersExceededWarning

慕婉清6462132 2023-03-24 14:23:31
我正在用風(fēng)數(shù)據(jù)(從 API JSON 中抓?。┨畛湟粋€(gè)數(shù)組,但出現(xiàn)錯(cuò)誤MaxListenersExceededWarning。我已經(jīng)查過了,這似乎是由于代碼中的錯(cuò)誤造成的。解決方法是設(shè)置setMaxListeners(n);,但顯然不推薦這樣做。任何人都可以看到是什么導(dǎo)致注冊(cè)了這么多聽眾嗎?什么是解決方案?我正在創(chuàng)建一個(gè)在請(qǐng)求時(shí)吐出數(shù)組的 API windRecordings。代碼const getWindForecast = (windRecordings) => {  setInterval(() => {    const instantWind = scrapeAPI(      "http://mobvaer.kystverket.no/v2/api/stations/5265049"    );    instantWind.then((res) => {      if (windRecordings.length > 0) {        // A wind value(s) is already pushed to the list        const latestRecordedWind = windRecordings[windRecordings.length - 1]; // get the first element out                // Compare the lates wind value in the list to the lates API request wind value        if (          latestRecordedWind[1]["Value"]["Value"] == res[1]["Value"]["Value"]        ) {          console.log("They are the same");        } else {            console.log("They are not the same, push them.")          windRecordings.push(res);        }      } else {        // The length is less than 0, no element has been added so far, push element        console.log("Push the first to the list");        windRecordings.push(res);      }    });    return windRecordings;  }, 1000);};錯(cuò)誤MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit(node:85830) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit(node:85830) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. Use emitter.setMaxListeners() to increase limit(node:85830) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit  });
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊

您每秒都在啟動(dòng)一個(gè)新的瀏覽器實(shí)例,并且不要關(guān)閉它們。


您的代碼執(zhí)行此操作:


  setInterval(() => {

    //const instantWind = scrapeAPI();

...

  const browser = await puppeteer.launch();

...

  }, 1000);

您需要關(guān)閉重用瀏覽器實(shí)例或至少關(guān)閉它們:


const scrapeAPI = async (url) => {

  const browser = await puppeteer.launch();

  const page = await browser.newPage();

  await page.goto(url);

  var content = await page.content();

  innerText = await page.evaluate(() => {

    return JSON.parse(document.querySelector("body").innerText);

  });


  const instantWind = innerText["Instantaneous"];

await browser.close();

  return instantWind;

};


查看完整回答
反對(duì) 回復(fù) 2023-03-24
  • 1 回答
  • 0 關(guān)注
  • 339 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)