New submission from Costas:

Background: We have two (clusters of) servers running a high-throughput 
websocket application. One runs under Python 2.7, the other has been migrated 
to 3.4. Very similar code runs on both servers, and both manually call the gc 
periodically to reduce latency. 

Problem: We noticed that under load the 3.4 server seems to slowly "leak" 
memory between gc collections, while the 2.7 server doesn't have this issue.

Investigation: I tracked down the source of all the garbage to 
email.feedparser, which is used by http.server to parse the headers of incoming 
requests. The initialiser of the FeedParser class creates a reference cycle by 
putting a lambda function into a member variable. The lambda contains a closure 
with its surrounding scope that points to the object, and the object points 
back to the lambda. 

Proposed fix: The lambda can be harmlessly replaced by a boolean value, which 
doesn't cause the problem, and it's much more readable too. I'm attaching a 
little patch.

----------
components: email
files: emailfeedparsergc.patch
keywords: patch
messages: 270503
nosy: Costas, barry, r.david.murray
priority: normal
severity: normal
status: open
title: Reference cycle in email.feedparser
type: resource usage
versions: Python 3.5
Added file: http://bugs.python.org/file43733/emailfeedparsergc.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27522>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to