Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 69f326d

Browse filesBrowse files
committed
ch20: README.adoc
1 parent f458063 commit 69f326d
Copy full SHA for 69f326d

File tree

Expand file treeCollapse file tree

1 file changed

+12
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-11
lines changed

‎20-futures/getflags/README.adoc

Copy file name to clipboardExpand all lines: 20-futures/getflags/README.adoc
+12-11Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
= Experimenting with the `flags2*` examples
22

33
The `flags2*` examples enhance the `flags*` examples with error handling and reporting.
4-
Therefore, we need a server that generates errors and delays to test them.
4+
Therefore, we need a server that generates errors and delays to experiment with them.
55

66
The main reason for these instructions is to document how to configure one such server
7-
in your machine, and how to run the clients to use it.
8-
7+
in your machine, and how to tell the `flags2*` clients to access it.
98
The other reason is to alert of an installation step that MacOS users sometimes overlook.
109

1110
Contents:
@@ -19,14 +18,14 @@ Contents:
1918

2019
If you don't already have a local HTTP server for testing,
2120
here are the steps to experiment with the `flags2*` examples
22-
using just the Python ≥ 3.9 distribution and
21+
using just the Python ≥ 3.9 distribution:
2322

2423
. Clone or download the https://github.com/fluentpython/example-code-2e[_Fluent Python 2e_ code repository] (this repo!).
2524
. Open your shell and go to the _20-futures/getflags/_ directory of your local copy of the repository (this directory!)
2625
. Unzip the _flags.zip_ file, creating a _flags_ directory at _20-futures/getflags/flags/_.
2726
. Open a second shell, go to the _20-futures/getflags/_ directory and run `python3 -m http.server`. This will start a `ThreadingHTTPServer` listening to port 8000, serving the local files. If you open the URL http://localhost:8000/flags/[http://localhost:8000/flags/] with your browser, you'll see a long list of directories named with two-letter country codes from `ad/` to `zw/`.
2827
. Now you can go back to the first shell and run the _flags2*.py_ examples with the default `--server LOCAL` option.
29-
. To test with the `--server DELAY` option, go to _20-futures/getflags/_ and run `python3 slow_server.py`. This bind to port 8001 by default. It will add a .5s delay before each response.
28+
. To test with the `--server DELAY` option, go to _20-futures/getflags/_ and run `python3 slow_server.py`. This binds to port 8001 by default. It will add a .5s delay before each response.
3029
. To test with the `--server ERROR` option, go to _20-futures/getflags/_ and run `python3 slow_server.py 8002 --error-rate .25`.
3130
Each request will have a 25% probability of getting a
3231
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418[418 I'm a teapot] response,
@@ -52,8 +51,7 @@ https://github.com/shopify/toxiproxy[Toxiproxy] with equivalent parameters.
5251

5352
The `flags2*` examples provide a command-line interface.
5453
All three scripts accept the same options,
55-
and you can see them by running any of the scripts with the `-h` option.
56-
<<flags2_help_demo>> shows the help text.
54+
and you can see them by running any of the scripts with the `-h` option:
5755

5856
[[flags2_help_demo]]
5957
.Help screen for the scripts in the flags2 series
@@ -91,18 +89,21 @@ One option you can't ignore is `-s/--server`: it lets you choose which HTTP serv
9189
You can pass one of four strings to determine where the script will look for the flags (the strings are case insensitive):
9290

9391
`LOCAL`:: Use `http://localhost:8000/flags`; this is the default.
94-
You should configure a local HTTP server to answer at port 8000. See <<setting_up_servers_box>> for instructions.
92+
You should configure a local HTTP server to answer at port 8000. See <<server_setup>> for instructions.
93+
Feel free to hit this as hard as you can. It's your machine!
9594

9695
`REMOTE`:: Use `http://fluentpython.com/data/flags`; that is a public website owned by me, hosted on a shared server.
97-
Please do not pound it with too many concurrent requests.
96+
Please do not hit it with too many concurrent requests.
9897
The `fluentpython.com` domain is handled by the http://www.cloudflare.com/[Cloudflare] CDN (Content Delivery Network)
9998
so you may notice that the first downloads are slower, but they get faster when the CDN cache warms
10099
up.footnote:[Before configuring Cloudflare, I got HTTP 503 errors--Service Temporarily Unavailable--when
101100
testing the scripts with a few dozen concurrent requests on my inexpensive shared host account. Now those errors are gone.]
102101

103-
`DELAY`:: Use `http://localhost:8001/flags`; a server delaying HTTP responses should be listening to port 8001. I wrote _slow_server.py_ to make it easier to experiment. You'll find it in the _20-futures/getflags/_ directory of the https://github.com/fluentpython/example-code-2e[_Fluent Python 2e_ code repository]. See <<setting_up_servers_box>> for instructions.
102+
`DELAY`:: Use `http://localhost:8001/flags`; a server delaying HTTP responses should be listening to port 8001.
103+
I wrote _slow_server.py_ to make it easier to experiment. See <<server_setup>> for instructions.
104104

105-
`ERROR`:: Use `http://localhost:8002/flags`; a server introducing HTTP errors and delaying responses should be installed at port 8002. Running _slow_server.py_ is an easy way to do it. See <<setting_up_servers_box>>.
105+
`ERROR`:: Use `http://localhost:8002/flags`; a server introducing HTTP errors and delaying responses should be installed at port 8002.
106+
Running _slow_server.py_ is an easy way to do it. See <<server_setup>>.
106107

107108
[[macos_certificates]]
108109
== Install SSL Certificates (for MacOS)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.