Author Costas
Recipients Costas, barry, r.david.murray
Date 2016-07-15.19:17:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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.
Date User Action Args
2016-07-15 19:17:55Costassetrecipients: + Costas, barry, r.david.murray
2016-07-15 19:17:55Costassetmessageid: <>
2016-07-15 19:17:54Costaslinkissue27522 messages
2016-07-15 19:17:54Costascreate