Skip to content

Commit 4222172

Browse files
authored
Expose sleep_loop for documentation and demo (#991)
Expose `sleep_loop` for documentation and demo
2 parents 14c3ce2 + e7e0315 commit 4222172

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,8 +1341,9 @@ if __name__ == '__main__':
13411341

13421342
Note that:
13431343

1344-
1. Calling `main` is simply equivalent to starting `proxy.py` from command line.
1345-
2. `main` doesn't accept any `*args`. It will automatically parse any available `sys.argv`.
1344+
1. `main` is equivalent to starting `proxy.py` from command line.
1345+
2. `main` does not accept any `args` (only `kwargs`).
1346+
3. `main` will automatically consume any available `sys.argv` as `args`.
13461347
3. `main` will block until `proxy.py` shuts down.
13471348

13481349
## Non-blocking Mode
@@ -1355,19 +1356,20 @@ import proxy
13551356

13561357
if __name__ == '__main__':
13571358
with proxy.Proxy() as p:
1358-
# ... your logic here ...
1359+
# Uncomment the line below and
1360+
# implement your app your logic here
1361+
proxy.sleep_loop()
13591362
```
13601363

13611364
Note that:
13621365

1363-
1. `Proxy` is similar to `main`, except `Proxy` does not block.
1364-
2. Internally `Proxy` is a context manager.
1365-
3. It will start `proxy.py` when called and will shut it down
1366-
once the scope ends.
1367-
4. However, unlike `main`, startup flags with `Proxy`
1368-
can also be customized by either passing flags as list of
1369-
input arguments e.g. `Proxy(['--port', '8899'])` or
1366+
1. `Proxy` is similar to `main`, except `Proxy` will not block.
1367+
2. Internally, `Proxy` is a context manager which will start
1368+
`proxy.py` when called and will shut it down once the scope ends.
1369+
3. Unlike `main`, startup flags with `Proxy` can also be customized
1370+
by using `args` and `kwargs`. e.g. `Proxy(['--port', '8899'])` or
13701371
by using passing flags as kwargs e.g. `Proxy(port=8899)`.
1372+
4. Unlike `main`, `Proxy` will not inspect `sys.argv`.
13711373

13721374
## Ephemeral Port
13731375

@@ -1381,6 +1383,7 @@ import proxy
13811383
if __name__ == '__main__':
13821384
with proxy.Proxy() as p:
13831385
print(p.flags.port)
1386+
proxy.sleep_loop()
13841387
```
13851388

13861389
`flags.port` will give you access to the random port allocated by the kernel.

proxy/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
from .proxy import entry_point, main, Proxy
11+
from .proxy import entry_point, main, Proxy, sleep_loop
1212
from .testing import TestCase
1313

1414
__all__ = [
@@ -22,4 +22,6 @@
2222
# https://github.com/abhinavsingh/proxy.py#unit-testing-with-proxypy
2323
'TestCase',
2424
'Proxy',
25+
# Utility exposed for demos
26+
'sleep_loop',
2527
]

0 commit comments

Comments
 (0)