Fix memory leak, refactor to be more pythonic maintainable, possibly faster. #4483

pull pygeek wants to merge 2 commits into bitcoin:master from pygeek:patch-1 changing 2 files +238 −221
  1. pygeek commented at 5:16 AM on July 8, 2014: contributor

    A memory leak has been fixed. After an http connection is open it is never closed. The loop method has been modified to close the connection upon completion.

    There have been several other changes, all of which are in accordance with standard practice in the Python community:

    • spaces instead of tabs
    • improved whitespace
    • correctly ordered import statements.
    • print functions instead of statements.
    • string format method instead of deprecated % syntax
    • setdefault method for setting dictionary defaults
    • among many other minor changes.

    Notes:

    • These changes have made it easier to understand and modify the codebase.
    • This code did not have tests; incorporating tests would require a more significant refactor. Due to the nature of my intended changes, I decided it was not necessary at this point to refactor to that extent.
    • This code did not have docstrings (See PEP 257: http://legacy.python.org/dev/peps/pep-0257/). In order to successfully refactor and test this in the future docstrings will prove helpful.
  2. jgarzik commented at 5:36 AM on July 8, 2014: contributor

    Looks mostly OK. I readily admit my python, like my JavaScript and C++, looks like it was written by a C coder.

    "Whoever created this file used tabs instead of spaces, which is very inconvenient to anyone that needs to edit this." is always met with a snort, because the reverse is true. Tabs enables custom indentation, spaces do not. Furthermore, after much reading of various python code from various authors, it is apparent that the Linus maxim continues to be true: 8-space-sized tabs lead to more readable code, because it forces the programmer to break up their code into small, readable units that just do one thing.

    PEP8 is no defense against the widespread "death before helper function" practice, in the python-writing bitcoin community at least, where 200 line, 200 column methods are the norm.

    But it is not your fault that the python community are anti-productive blockheads in this regard, so the likely course is to accept PEP8 with all its idiocy (and these changes).

  3. pygeek commented at 5:50 AM on July 8, 2014: contributor

    Honestly, I agree with you to an extent. However, I tend to follow set practices according to the language I'm contributing to—just as a courtesy to anyone else that needs to read or modify my code. No offense intended, nor taken.

  4. laanwj commented at 7:13 AM on July 8, 2014: member

    ACK after squashing to one commit. As these are all minimal syntactic changes, we don't need this level of detail.

  5. laanwj commented at 7:40 AM on July 8, 2014: member

    BTW, as an aside, not necessary to be done in this pull, this script needs to be changed to use getblocktemplate instead of getwork. Getwork was removed 2 weeks ago in cf0c47b.

  6. test/bloom_tests: Use UL suffix for unsigned long number to ensure compatibility ecc1360d7b
  7. Fix memory leak, refactor to be more pythonic, maintainable, and possibly faster. 7f6fa9bc5c
  8. pygeek commented at 9:46 PM on July 8, 2014: contributor

    Rebased, luke-jr's commit somehow got rolled into this pull-request.

  9. BitcoinPullTester commented at 10:39 PM on July 8, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4483_7f6fa9bc5cf0601c7f2f8dba933011f276d746cf/ for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  10. laanwj commented at 11:25 AM on July 14, 2014: member

    Seems something went wrong while rebasing, I still see @luke-jr's bloom change in here.

  11. laanwj referenced this in commit 9192ca9e33 on Jul 25, 2014
  12. laanwj commented at 8:59 AM on July 25, 2014: member

    Cherry-picked as 9192ca9.

  13. laanwj closed this on Jul 25, 2014

  14. MathyV referenced this in commit 6cd539c31a on Nov 24, 2014
  15. reddink referenced this in commit cc0a9384ef on May 27, 2020
  16. bitcoin locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:55 UTC