[2.7] bpo-27973 - Fix for urllib.urlretrieve() failing on second ftp transfer#1040
[2.7] bpo-27973 - Fix for urllib.urlretrieve() failing on second ftp transfer#1040orsenthil merged 2 commits into
Conversation
| Library | ||
| ------- | ||
|
|
||
| - bpo-27973 - Fix for urllib.urlretrieve() failing on second ftp transfer. |
There was a problem hiding this comment.
Missed :. The second - is not needed.
| try: | ||
| for _ in range(3): | ||
| fp = urllib.urlopen(self.FTP_TEST_FILE) | ||
| # closing fp is not required. |
There was a problem hiding this comment.
This test can behave differently in CPython and PyPy. If fp can remain unclosed, maybe save it in a list, so that it will not be closed in all implementations? If the file is not closed explicitly it is worth to call test_support.gc_collect() after removing all references to it. This will make the behavior more predicable in all implementations.
| for _ in range(3): | ||
| urllib.FancyURLopener().retrieve( | ||
| self.FTP_TEST_FILE, | ||
| tempfile.NamedTemporaryFile().name) |
There was a problem hiding this comment.
The NamedTemporaryFile object can be collected right after getting its name. Save a reference to tempfile.NamedTemporaryFile() until retrieve a file or better use a context manager.
|
Has this fix stalled? I'm able to reproduce this problem in Python 2.7.13 with the following steps:
These steps result in this error: |
|
|
||
|
|
||
| class urlopen_FTPTest(unittest.TestCase): | ||
| # TODO: https://github.com/python/pythondotorg/issues/1069 |
There was a problem hiding this comment.
It seems that this TODO is no longer needed.
|
|
||
| with test_support.transient_internet(self.FTP_TEST_FILE): | ||
| try: | ||
| for _ in range(3): |
There was a problem hiding this comment.
for _ in range(3): is used a couple of times in this class. I think the 3 should be replaced with a constant.
| fp = urllib.urlopen(self.FTP_TEST_FILE) | ||
| # closing fp is not required. | ||
| except IOError as e: | ||
| self.fail("Failed FTP binary file open." |
There was a problem hiding this comment.
There should be a space after this period (or a space just before the "Error" on the next line).
benjaminp
left a comment
There was a problem hiding this comment.
If you still want to pursue this, it will need to be rebased and blurbed.
|
When you're done making the requested changes, leave the comment: |
|
I have made the requested changes; please review again. @benjaminp - Please take a call to include the final 2.7 release. Thanks. |
|
Thanks for making the requested changes! @benjaminp: please review the changes made to this pull request. |
benjaminp
left a comment
There was a problem hiding this comment.
Since this is essentially a revert, it seems good.
|
@orsenthil: Please replace |
|
This PR is failing in several 2.7 buildbots: Example failure: |
The problem and the solution has been described well in the msg: http://bugs.python.org/issue27973#msg286016
This just brings the patch to github.
https://bugs.python.org/issue27973