diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-11-16 15:16:18 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-11-16 15:16:18 +0100 |
commit | b704146516631f5e561b50ae3a1154f306ffb955 (patch) | |
tree | 0e4ece80fdf220829f014f3edb4537a78d32b6c4 /randport | |
parent | 58adf7f5e50e437a445213964298f6bfe0c39fb4 (diff) | |
download | qvisqve-b704146516631f5e561b50ae3a1154f306ffb955.tar.gz |
Add: beginnings of a yarn test suite
Diffstat (limited to 'randport')
-rwxr-xr-x | randport | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/randport b/randport new file mode 100755 index 0000000..d523401 --- /dev/null +++ b/randport @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +# +# Copyright (C) 2017 Lars Wirzenius +# +# Pick a random port that is free to be listened on. For testing. + + +import errno +import random +import socket +import sys + + +MAX = 1000 +for i in range(MAX): + port = random.randint(1025, 2**15-1) + s = socket.socket() + try: + s.bind(('0.0.0.0', port)) + except OSError as e: + if e.errno == errno.EADDRINUSE: + continue + raise + break +else: + sys.stderr.write("Can't find a free port\n") + sys.exit(1) +sys.stdout.write('{}\n'.format(port)) |