Windows Specific Issue and work-around: Chapter 17: flags2_common.py
Opened this issue · 2 comments
First of all - a well written and complete book for intermediate to advanced Python users. It covers a lot of territory and for the most part will work as is on a variety of systems. I did find one bug in chapter 17 that prevents you from moving through the last part of the chapter. The error is in flags2_common.py on Windows 8-10: Not sure if this effects other systems too. The code provided is this...
def main(download_many, default_concur_req, max_concur_req):
args, cc_list = process_args(default_concur_req)
actual_req = min(args.max_req, max_concur_req, len(cc_list))
initial_report(cc_list, actual_req, args.server)
base_url = SERVERS[args.server]
t0 = time.time()
counter = download_many(cc_list, base_url, args.verbose, actual_req)
assert sum(counter.values()) == len(cc_list), \
'some downloads are unaccounted for'
final_report(cc_list, counter, t0)
For windows, this will throw an error: This code works better...
def main(download_many, default_concur_req, max_concur_req):
args, cc_list = process_args(default_concur_req)
actual_req = min(args.max_req, max_concur_req, len(cc_list))
initial_report(cc_list, actual_req, args.server)
base_url = SERVERS[args.server]
t0 = time.time()
counter = download_many(cc_list, base_url, args.verbose, actual_req)
assert sum(counter.values()) == len(cc_list), 'some downloads are unaccounted for'
final_report(cc_list, counter, t0)
Let me know if you need clarification.
What is the error you get. The only thing different here is that you've removed the line wrap on the assert statement which a) shouldn't be a problem or throw an error and b) puts the line longer than 80 characters which is a violation of PEP 8 as seen here:
https://www.python.org/dev/peps/pep-0008/#maximum-line-length
Oddly enough, a syntax error, reproducing it minus personal information which I've substituted - we get this. This is a workaround - not a fix. 80 width on an editor may be an issue, since this is 82 characters.
I'll close if something here is trivial and being overlooked, but it seemed off...
Error:
`Traceback (most recent call last):
File "flags2_threadpool.py", line 49, in
from flags2_common import main, HTTPStatus # <2>
File "C:\countries\flags2_common.py", line 294
^
SyntaxError: invalid syntax`
so... say I'm running flags2_threadpool.py: Then you change flags2_common.py to my version, which is 2 characters in violation of PEP 8, therefor not a fix, but a workaround...
`PS C:\countries> py -3 flags2_threadpool.py
LOCAL site: http://localhost:8001/flags
Searching for 20 flags: from BD to VN
20 concurrent connections will be used.
100%|######################################################################################################################| 20/20 [00:01<00:00, 12.67it/s]
20 flags downloaded.
Elapsed time: 1.62s`
Is this a space case error on my part, or a legit one? I'm having trouble finding a documented version of something similar, so it may be human error of course, somehow, but it seemed like an interpreter problem or something else, so I thought I'd see what the community thought.
Using visual studio 2015 enterprise. The error didn't make sense to me but it's thrown and won't allow flags2_* scripts to run unless you take away the wrap and one line it. I said a work-around because it does violate the principle outlined in PEP 8, but allows you to continue moving if you're encountering an error too - I've since finished the book and didn't have any other problem cases. It didn't make sense to me, but it was the only way the script works as is. Violating a PEP by 2 characters.
Also, I tried toggling word wrap on/off in Visual Studio - didn't make a difference. Went through a couple sanity checks, just didn't get any progress without one-lining.
Any suggestions?