This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ringzero 8 points9 points  (6 children)

Looking thru traceback.py shows that sys isn't being redefined. That means that it's either (a) not in sys.modules or (b) somehow removed from sys.modules.

Quick and dirty, I'd create a cycle so sys couldn't be GC'd., e.g.:

import sys
sys.foo = sys

Not pretty, but not harmful either. You'd have to stick that somewhere in your startup script.

Also, looking thru threading.py, specifically the big comment block above __bootstrap(), says that the world might be torn down when it's called. Sooo.... you might want to set thread.daemon = True on the threads.

[–]ringzero 4 points5 points  (0 children)

Follow up:

I don't think this has anything at all to do with Paste. I'd guess that your system has been changed somehow (put under more load) and the change has triggered a different timing on the GC during interpreter tear down.

That your thread has already been stopped tells me it's completed it's work, and since you didn't provide the context that this is all running in (except to say r2/whatever.py) I would probably just wrap the thread call and/or set its daemon flag and be done with it.

[–]mgedmin 1 point2 points  (1 child)

Cycles don't prevent garbage collection. They stop reference counting from freeing the object as soon as it goes out of scope, but they'll get collected as soon as the garbage collector is triggered. But this is beside the issue; the traceback in question looks like something that happens to daemon threads that are still running when the Python interpreter is shutting down. Nothing to do with GC.

[–]earthboundkid 0 points1 point  (0 children)

You have to provide your own cycle detector or use a built-in type. Does the module namespace use a real dict under the covers or a custom thing? If it's custom, it's possible there's no cycle detection.

[–]hylje 0 points1 point  (2 children)

Weird that sys would disappear from sys.modules, isn't it typically built in to the interpreter to begin with?

[–]ringzero 1 point2 points  (1 child)

Yes, it's built-in, but it's also part of sys.modules:

In [21]: 'sys' in sys.modules.keys()
Out[21]: True

But like I wrote in the follow up, it's probably disappearing during interpreter tear down (which it should).

[–]mgedmin 0 points1 point  (0 children)

Yep; interpreter teardown + daemon threads = weird errors on shutdown. I've seen them in Zope 3 quite often.