-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split off random port selection into a separate callable.
- Allows selection of random ports within a certain range only as a first use case. - Closes: #102 via a different strategy. - Currently uses the traitlet Any, but should be Callable - but this is not in upstream traitlets, it is special to kubespawner. So leave Any for now and change later.
- Loading branch information
Showing
4 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Miscellaneous utilities | ||
|
||
import random | ||
|
||
def random_port_range(low, high): | ||
"""Factory function to select a random port number in the range [low,high]. | ||
Usage: c.BatchSpawner.random_port = random_port_range(low, high) | ||
""" | ||
# TODO: This does not prevent port number conflicts like | ||
# jupyterhub/utils.random_port tries to do. But we actually | ||
# can't, because we run on a different host, so | ||
# jupyterhub.utils.random_port actually doesn't work for us. #58 | ||
# tries to do this better. | ||
return lambda: random.randint(low, high) |