0

Seemingly out of nowhere, whenever I called the url for my Django model, be it with ListView or DetailView, it would hang, and while doing so the memory would spike and I had to kill runserver. I have now tracked this issue down to subprocess._try_wait(). The simple solution seems to be to raise ChildProcessError. But this is source code, and I've always been told not to mess with source. So how am I supposed to fix this? With a decorator? That still has to go in the source, doesn’t it? Please advise.

Also, I note that there is a comment in the source code about a python bug in the method immediately preceding _try_wait(), which is _internal_poll(). See http://bugs.python.org/issue15756 . However, that bug was reported and fixed all the way back in 2012, and it was thought to be identical to 1731717, reported all the way back in 2007 and fixed in Python 3.2. This project is my first on Python 3.9.9, so I am hoping this bug has not been re-introduced. Django is 3.2.9, os is Ubuntu 20.04.

Also, all these comments and bug reports talk about “SIGCLD is set to be ignored.” But if that’s the better way to go, how would I do that? I know nothing about C code.

What is the use of ignoring `SIGCHLD` signal with `sigaction(2)`?

What exactly SIG_DFL do?

How can I handle SIGCHLD?

Finally, I noticed that none of these sources mention memory spikes. I’m not sure if that makes a difference or not. I am assuming that a memory leak == what I am calling a memory spike. Again, thank you.

Malik A. Rumi
  • 1,855
  • 4
  • 25
  • 36
  • What is the context of this? [`manage.py runserver` is only meant to be used for development](https://docs.djangoproject.com/en/4.0/ref/django-admin/#runserver): "DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making web frameworks, not web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)" – ChrisGPT was on strike Dec 17 '21 at 23:16
  • Well, you should look for a memory leaking bug in your code before claiming it is an interpreter or framework bug. In any case please present a minimal reproducible example. – Klaus D. Dec 17 '21 at 23:40
  • @Chris No, not at all. I followed the Profiler from manage.py all the way to the try_wait function inside the subprocess module, so at this point we are out of Django and into pure Python. – Malik A. Rumi Dec 21 '21 at 22:02
  • @KlausD. I didn't post any code here because all the red boxes in PyCharm's profiler were source code, not my own. Even when I used the debugger to 'step into my own code' I got nothing. That's why I posted the way I did, hoping to at least get some helpful hints. Once I killed the child process, waitpid() returned the tuple, like it is supposed to, which is why I thought finding a way to trigger that, since it wasn't triggering automatically like it should, would be the way to go. I just wasn't sure about doing that in source. – Malik A. Rumi Dec 21 '21 at 22:12

0 Answers0