Skip to content

Commit e1b7928

Browse files
seewindcnA. Jesse Jiryu Davis
authored andcommitted
Update thread_util.py
Pool object call GreenletIdent.watch(on_thread_died) and not unlink. if the greenlet is resident, greenlet._links is growth
1 parent 280a7fc commit e1b7928

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pymongo/thread_util.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,25 @@ def watch(self, callback):
119119
# This is a Gevent Greenlet (capital G), which inherits from
120120
# greenlet and provides a 'link' method to detect when the
121121
# Greenlet exits.
122-
current.link(callback)
123-
self._refs[tid] = None
122+
from gevent.greenlet import SpawnedLink
123+
sl = SpawnedLink(callback)
124+
current.rawlink(sl)
125+
self._refs[tid] = sl
126+
#current.link(callback)
127+
#self._refs[tid] = None
124128
else:
125129
# This is a non-Gevent greenlet (small g), or it's the main
126130
# greenlet.
127131
self._refs[tid] = weakref.ref(current, callback)
128132

129-
133+
def unwatch(self):
134+
""" call unlink if link before """
135+
sl = self._refs.pop(self.get(), None)
136+
current = greenlet.getcurrent()
137+
if hasattr(current, 'link'):
138+
current.unlink(sl)
139+
140+
130141
def create_ident(use_greenlets):
131142
if use_greenlets:
132143
return GreenletIdent()

0 commit comments

Comments
 (0)