forked from eventlet/eventlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tpool: exception in tpool-ed call leaked memory via backtrace
eventlet#469 eventlet#470 https://cosmicpercolator.com/2016/01/13/exception-leaks-in-python-2-and-3/
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
__test__ = False | ||
|
||
if __name__ == '__main__': | ||
import eventlet | ||
import eventlet.tpool | ||
import gc | ||
import pprint | ||
|
||
class RequiredException(Exception): | ||
pass | ||
|
||
class A(object): | ||
def ok(self): | ||
return 'ok' | ||
|
||
def err(self): | ||
raise RequiredException | ||
|
||
a = A() | ||
|
||
# case 1 no exception | ||
assert eventlet.tpool.Proxy(a).ok() == 'ok' | ||
# yield to tpool_trampoline(), otherwise e.send(rv) have a reference | ||
eventlet.sleep(0.1) | ||
gc.collect() | ||
refs = gc.get_referrers(a) | ||
assert len(refs) == 1, 'tpool.Proxy-ied object leaked: {}'.format(pprint.pformat(refs)) | ||
|
||
# case 2 with exception | ||
def test_exception(): | ||
try: | ||
eventlet.tpool.Proxy(a).err() | ||
assert False, 'expected exception' | ||
except RequiredException: | ||
pass | ||
test_exception() | ||
# yield to tpool_trampoline(), otherwise e.send(rv) have a reference | ||
eventlet.sleep(0.1) | ||
gc.collect() | ||
refs = gc.get_referrers(a) | ||
assert len(refs) == 1, 'tpool.Proxy-ied object leaked: {}'.format(pprint.pformat(refs)) | ||
|
||
print('pass') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters