Python GC does not work as it should be

J

Jaimy Azle

See this piece of code:

/* API to invoke gc.collect() from C */
Py_ssize_t
PyGC_Collect(void)
{
Py_ssize_t n;

if (collecting)
n = 0; /* already collecting, don't do anything */
else {
collecting = 1;
n = collect(NUM_GENERATIONS - 1);
collecting = 0;
}
return n;
}

If a system exception raised when executing collect(xxx), collecting state
variable would never be reset and python GC will not works forever until the
application restarted. Perhaps it is a rare situation on normal usage, i
mean if 100% code written in python. I use python as an embedded engine on a
multithreaded server handling business process script which written in
python. Though at last i found my code that causing it and fixed, i still
think those code still has a potential problem on a long running process (as
server side scripting language). My workaround limited to implementation
with MSVC, I wrap those code in an exception trapper, and force to reset
collecting variable.

Salam,

-Jaimy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top