Python剧作家内存覆盖

mwkjh3gx  于 2023-02-15  发布在  Python
关注(0)|答案(2)|浏览(183)

我做了一个代码,刮一个网站连续几次后,得到了这个消息

<--- Last few GCs --->

[17744:00000270608DE2C0] 16122001 ms: Scavenge 2023.5 (2082.0) ->
2017.3 (2082.5) MB, 3.6 / 0.1 ms  (average mu = 0.908, current mu = 0.941) task [17744:00000270608DE2C0] 16122645 ms: Scavenge 2023.9 (2082.5) -> 2017.7 (2083.0) MB, 3.5 / 0.0 ms  (average mu = 0.908, current mu = 0.941) task  [17744:00000270608DE2C0] 16128334 ms: Scavenge 2024.1 (2083.0) -> 2017.7 (2099.0) MB, 4.7 / 0.0 ms  (average mu = 0.908, current mu = 0.941) task 

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory  1: 00007FF66A07013F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112495  2: 00007FF669FFF396 DSA_meth_get_flags+65526  3: 00007FF66A00024D node::OnFatalError+301  4: 00007FF66A9319EE v8::Isolate::ReportExternalAllocationLimitReached+94  5: 00007FF66A91BECD v8::SharedArrayBuffer::Externalize+781  6: 00007FF66A7BF61C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468  7: 00007FF66A7BC754 v8::internal::Heap::CollectGarbage+4244  8: 00007FF66A76C3B5 v8::internal::IndexGenerator::~IndexGenerator+22165  9: 00007FF669F90E9F v8::CFunctionInfo::HasOptions+22111 10: 00007FF669F8F6B6 v8::CFunctionInfo::HasOptions+15990 11: 00007FF66A0CF25B uv_async_send+331 12: 00007FF66A0CE9EC uv_loop_init+1292 13: 00007FF66A0CEB8A uv_run+202 14: 00007FF66A09DC95 node::SpinEventLoop+309 15: 00007FF669FB7AC3 cppgc::internal::NormalPageSpace::linear_allocation_buffer+53827 16: 00007FF66A034FBD node::Start+221 17: 00007FF669E588CC RC4_options+348108 18: 00007FF66AEB08F8 v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+14472 19: 00007FFEB62C7034 BaseThreadInitThunk+20 20: 00007FFEB78A2651 RtlUserThreadStart+33

在那之后我的代码就停止工作了。有谁遇到过这个问题知道怎么解决吗?我用的是python 3.8.8和playwright 1.22.0
我导入了这个库来制作网页

from playwright.sync_api import sync_playwright

谢谢你们!

wpcxdonn

wpcxdonn1#

请参考此堆栈溢出链接了解更多详细信息。希望这将有助于解决您的问题

mdfafbf1

mdfafbf12#

对于2023年第1季度,这可能是最佳对策:https://github.com/microsoft/playwright/issues/6319#issuecomment-1227405461
在创建浏览器/上下文并执行满足您的需要所需的操作后,将浏览器的状态保存到本地文件(会话、本地存储等):
context.StorageState("state.json")
关闭浏览器,关闭上下文,每隔30分钟杀死所有node.exe进程。(这就是内存泄漏的地方),如果你不杀死它们,它每次都会创建一个单独的node.exe进程。
创建新的浏览器/上下文并以保存状态加载。导航回您需要的位置。context, err := browser.NewContext( playwright.BrowserNewContextOptions{ StorageStatePath: playwright.String("state.json"), })
在记忆问题的情况下,剧作家阅读整个问题,所以也许你会发现一些灵感:https://github.com/microsoft/playwright/issues/6319

相关问题