Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1341,8 +1341,9 @@ if __name__ == '__main__':

Note that:

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

## Non-blocking Mode
Expand All @@ -1355,19 +1356,20 @@ import proxy

if __name__ == '__main__':
with proxy.Proxy() as p:
# ... your logic here ...
# Uncomment the line below and
# implement your app your logic here
proxy.sleep_loop()
```

Note that:

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

## Ephemeral Port

Expand All @@ -1381,6 +1383,7 @@ import proxy
if __name__ == '__main__':
with proxy.Proxy() as p:
print(p.flags.port)
proxy.sleep_loop()
```

`flags.port` will give you access to the random port allocated by the kernel.
Expand Down
4 changes: 3 additions & 1 deletion proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
from .proxy import entry_point, main, Proxy
from .proxy import entry_point, main, Proxy, sleep_loop
from .testing import TestCase

__all__ = [
Expand All @@ -22,4 +22,6 @@
# https://github.com/abhinavsingh/proxy.py#unit-testing-with-proxypy
'TestCase',
'Proxy',
# Utility exposed for demos
'sleep_loop',
]