Closed ninjaclown123 closed 1 month ago
Is there a way to terminate the workers that are started in my process?
reach the script in case, then script.xworker.terminate()
is all you need. It's WebWorker standard API by all means.
About this report ... if you create gazillion workers you gonna have issues no matter if PyScript or not ... I suggest you don't do that.
Closing as no follow up happened so I suppose the hint around terminating the worker helped.
Checklist
What happened?
I seem to be running into a memory leak because of the way I'm using PyScript in my project.
My project requires the following cycle to happen:
This is a modified section to show as an example but in actual usage, I am taking a python program that is written in a code editor, creating the above script element, setting the type to "py", setting worker attribute and terminal attribute and changing the innerHTML to the code of the python program. When the new script is appended to the result div, I can see the python program executed in the terminal window.
The above is equivalent to:
In the above example, I have executed the above with a simple print.
The problem that I have now is that this eventually leads to a memory issue.
It seems to happen after running the above process 50 times. I inspected the Memory tab in chrome dev tools and found that it may be due to the workers created with each script not being freed when I clear the DOM. It seems to happen when the total heap size goes beyond 400~410 MB.
Is there a way to terminate the workers that are started in my process?
Or, since the Web Worker API has terminate() and close() methods, is there any way to start the same workers but by using the Web Worker API?
Instead of making new pyscript instances, I have also tried using the same instance and using .process() to execute my programs too like here. However, this was kind of clunky for me as the programs written in the code editor would get executed line by line and sometimes they would get entered into the REPL but wouldn't execute at all and would needed to get cleared.
I've tried looking for ways to clear or terminate the workers myself but could not find anything. Maybe there's a better way of doing my process and it would be appreciated to get some direction if that's the case.
What browsers are you seeing the problem on? (if applicable)
Chrome
Console info
Additional Context
Sources tab when the memory issue occurs:![image](https://github.com/pyscript/pyscript/assets/135505235/8a918397-f7ef-4720-a35e-b2a5a4a7d8ee)
class.js:![image](https://github.com/pyscript/pyscript/assets/135505235/306b8ba6-23f3-472a-98c9-0bc0ef86fb9c)