0

I am working on a piece of legacy code that has to run asynchronously, but unfortunately, this code causes a memory leak (it is unreachable for me to make changes). Code runs in executor inside asyncio loop aside event hub consumer. Is it possible to not reuse the same process but spawn a new one or somehow clear this process' cache?

Jesse Squire
  • 6,107
  • 1
  • 27
  • 30
kamroj
  • 23
  • 4
  • Pardo I was about to write `ProcessPoolExecutor`. What I mean I have got a piece of code that causes a memory leak and the one and the only solution would be to recreate the process each time the task is handled by that process pool. I am not able to fix the problem with the memory leak but if somehow I would be able to spawn a brand new process each time that would potentially solve my issue. – kamroj Jul 09 '21 at 10:31
  • Yes, you're right. I've just edited the main question. – kamroj Jul 09 '21 at 11:15
  • 1
    You can close the executor and create a new one when you need to create a fresh process. – user4815162342 Jul 09 '21 at 18:04
  • Also, take a look at the approach used in [this answer](https://stackoverflow.com/a/52938384/1600898) which builds a pool from multiple individual pools. You could adapt it to your use case by closing the pool and getting a new one even if the future has completed without getting canceled. – user4815162342 Jul 10 '21 at 20:57

0 Answers0