jaraco / portend Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
As per $SUBJ, it should probably be sent there :)
I use 'CherryPy' package that depend on 'portend'.
'portend' require 'jaraco.timing'.
'jaraco.timing' is deprecated and replaced with 'tempora.timing'.
Unfortunately, I can't packaging my app with 'jaraco.timing' using py2exe.
When use 'tempora.timing', my app is packaged using py2exe and works well.
(I modify the line 20 in the portend.py)
from jaraco import timing
->
from tempora import timing
Below is my test.
# test_jaracotiming.py
from jaraco import timing
print "jaraco.timing"
# setup_jaracotiming.py
from distutils.core import setup
import py2exe
setup(console=['test_jaracotiming.py'])
D:\work\py2exe_test>python setup_jaracotiming.py py2exe -c
D:\work\py2exe_test\dist>test_jaracotiming.exe
Traceback (most recent call last):
File "test_jaracotiming.py", line 1, in <module>
ImportError: No module named jaraco
# test_temporatiming.py
from tempora import timing
print "tempora.timing"
# setup_temporatiming.py
from distutils.core import setup
import py2exe
setup(console=['test_temporatiming.py'])
D:\work\py2exe_test>python setup_temporatiming.py py2exe -c
D:\work\py2exe_test\dist>test_temporatiming.exe
tempora.timing
Hey-lo,
I'm building a version of portend
using conda
for conda-forge. When possible, we try to include a link to the license file in the meta.yaml
specification for the build; doing so requires an actual license file be bundled with the dist and (usually) that said license be indexed in an explicit MANIFEST.in
file so that it gets included in the source distribution.
Would you consider adding a full copy of the MIT License to the bundle, along with an appropriate manifest?
In the port check routine, there is a fallback for when getaddrinfo raises an error. It's not obvious to me why that functionality exists or if it still serves as a purpose. Perhaps it's cruft from an older Python, or perhaps it's to support environments that are no longer in use, or perhaps it serves a real purpose.
Let's raise a warning when this functionality is used and see if anyone is using it.
I'm trying to package your module as an rpm package. So I'm using the typical build, install and test cycle used on building packages from non-root account.
Looks like pytest is failing on hosts without ipv6:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-portend-3.1.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-portend-3.1.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
rootdir: /home/tkloczko/rpmbuild/BUILD/portend-3.1.0, configfile: pytest.ini
plugins: shutil-1.7.0, virtualenv-1.7.0, mock-3.6.1, cov-2.12.1, anyio-3.3.4, forked-1.3.0, xdist-2.3.0, flaky-3.7.0, tornasync-0.6.0.post2, console-scripts-1.2.0, trio-0.7.0, timeout-2.0.1, asyncio-0.16.0, hypothesis-6.27.0, freezegun-0.4.2, flake8-1.0.7
collected 20 items
portend.py F...FF [ 30%]
test_portend.py .E.F.F.E.E.E.E [100%]
================================================================================== ERRORS ==================================================================================
_____________________________________________ ERROR at setup of TestChecker.test_check_port_listening[AddressFamily.AF_INET6] ______________________________________________
request = <SubRequest 'listening_addr' for <Function test_check_port_listening[AddressFamily.AF_INET6]>>
@pytest.fixture(**build_addr_infos())
def listening_addr(request):
af, socktype, proto, canonname, sa = request.param
> sock = socket.socket(af, socktype, proto)
test_portend.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, family = <AddressFamily.AF_INET6: 10>, type = <SocketKind.SOCK_STREAM: 1>, proto = 6
fileno = None
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
# For user code address family and type values are IntEnum members, but
# for the underlying _socket.socket they're just integers. The
# constructor of _socket.socket converts the given argument to an
# integer automatically.
if fileno is None:
if family == -1:
family = AF_INET
if type == -1:
type = SOCK_STREAM
if proto == -1:
proto = 0
> _socket.socket.__init__(self, family, type, proto, fileno)
E OSError: [Errno 97] Address family not supported by protocol
/usr/lib64/python3.8/socket.py:231: OSError
_______________________________________________ ERROR at setup of TestChecker.test_free_with_timeout[AddressFamily.AF_INET6] _______________________________________________
request = <SubRequest 'listening_addr' for <Function test_free_with_timeout[AddressFamily.AF_INET6]>>
@pytest.fixture(**build_addr_infos())
def listening_addr(request):
af, socktype, proto, canonname, sa = request.param
> sock = socket.socket(af, socktype, proto)
test_portend.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, family = <AddressFamily.AF_INET6: 10>, type = <SocketKind.SOCK_STREAM: 1>, proto = 6
fileno = None
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
# For user code address family and type values are IntEnum members, but
# for the underlying _socket.socket they're just integers. The
# constructor of _socket.socket converts the given argument to an
# integer automatically.
if fileno is None:
if family == -1:
family = AF_INET
if type == -1:
type = SOCK_STREAM
if proto == -1:
proto = 0
> _socket.socket.__init__(self, family, type, proto, fileno)
E OSError: [Errno 97] Address family not supported by protocol
/usr/lib64/python3.8/socket.py:231: OSError
________________________________________ ERROR at setup of TestChecker.test_occupied_with_immediate_timeout[AddressFamily.AF_INET6] ________________________________________
request = <SubRequest 'listening_addr' for <Function test_occupied_with_immediate_timeout[AddressFamily.AF_INET6]>>
@pytest.fixture(**build_addr_infos())
def listening_addr(request):
af, socktype, proto, canonname, sa = request.param
> sock = socket.socket(af, socktype, proto)
test_portend.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, family = <AddressFamily.AF_INET6: 10>, type = <SocketKind.SOCK_STREAM: 1>, proto = 6
fileno = None
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
# For user code address family and type values are IntEnum members, but
# for the underlying _socket.socket they're just integers. The
# constructor of _socket.socket converts the given argument to an
# integer automatically.
if fileno is None:
if family == -1:
family = AF_INET
if type == -1:
type = SOCK_STREAM
if proto == -1:
proto = 0
> _socket.socket.__init__(self, family, type, proto, fileno)
E OSError: [Errno 97] Address family not supported by protocol
/usr/lib64/python3.8/socket.py:231: OSError
___________________________________________________________ ERROR at setup of test_main[AddressFamily.AF_INET6] ____________________________________________________________
request = <SubRequest 'listening_addr' for <Function test_main[AddressFamily.AF_INET6]>>
@pytest.fixture(**build_addr_infos())
def listening_addr(request):
af, socktype, proto, canonname, sa = request.param
> sock = socket.socket(af, socktype, proto)
test_portend.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, family = <AddressFamily.AF_INET6: 10>, type = <SocketKind.SOCK_STREAM: 1>, proto = 6
fileno = None
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
# For user code address family and type values are IntEnum members, but
# for the underlying _socket.socket they're just integers. The
# constructor of _socket.socket converts the given argument to an
# integer automatically.
if fileno is None:
if family == -1:
family = AF_INET
if type == -1:
type = SOCK_STREAM
if proto == -1:
proto = 0
> _socket.socket.__init__(self, family, type, proto, fileno)
E OSError: [Errno 97] Address family not supported by protocol
/usr/lib64/python3.8/socket.py:231: OSError
_______________________________________________________ ERROR at setup of test_main_timeout[AddressFamily.AF_INET6] ________________________________________________________
request = <SubRequest 'listening_addr' for <Function test_main_timeout[AddressFamily.AF_INET6]>>
@pytest.fixture(**build_addr_infos())
def listening_addr(request):
af, socktype, proto, canonname, sa = request.param
> sock = socket.socket(af, socktype, proto)
test_portend.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, family = <AddressFamily.AF_INET6: 10>, type = <SocketKind.SOCK_STREAM: 1>, proto = 6
fileno = None
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
# For user code address family and type values are IntEnum members, but
# for the underlying _socket.socket they're just integers. The
# constructor of _socket.socket converts the given argument to an
# integer automatically.
if fileno is None:
if family == -1:
family = AF_INET
if type == -1:
type = SOCK_STREAM
if proto == -1:
proto = 0
> _socket.socket.__init__(self, family, type, proto, fileno)
E OSError: [Errno 97] Address family not supported by protocol
/usr/lib64/python3.8/socket.py:231: OSError
================================================================================= FAILURES =================================================================================
__________________________________________________________________ [doctest] portend.Checker.assert_free ___________________________________________________________________
045
046 Assert that the given addr is free
047 in that all attempts to connect fail within the timeout
048 or raise a PortNotFree exception.
049
050 >>> free_port = find_available_local_port()
051
052 >>> Checker().assert_free('localhost', free_port)
UNEXPECTED EXCEPTION: OSError(97, 'Address family not supported by protocol')
Traceback (most recent call last):
File "/usr/lib64/python3.8/doctest.py", line 1336, in __run
exec(compile(example.source, filename, "single",
File "<doctest portend.Checker.assert_free[1]>", line 1, in <module>
File "/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py", line 71, in assert_free
list(itertools.starmap(self._connect, info))
File "/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py", line 74, in _connect
s = socket.socket(af, socktype, proto)
File "/usr/lib64/python3.8/socket.py", line 231, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
OSError: [Errno 97] Address family not supported by protocol
/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py:52: UnexpectedException
__________________________________________________________________________ [doctest] portend.free __________________________________________________________________________
099
100 Wait for the specified port to become free (dropping or rejecting
101 requests). Return when the port is free or raise a Timeout if timeout has
102 elapsed.
103
104 Timeout may be specified in seconds or as a timedelta.
105 If timeout is None or ∞, the routine will run indefinitely.
106
107 >>> free('localhost', find_available_local_port())
UNEXPECTED EXCEPTION: OSError(97, 'Address family not supported by protocol')
Traceback (most recent call last):
File "/usr/lib64/python3.8/doctest.py", line 1336, in __run
exec(compile(example.source, filename, "single",
File "<doctest portend.free[0]>", line 1, in <module>
File "/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py", line 122, in free
Checker(timeout=0.1).assert_free(host, port)
File "/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py", line 71, in assert_free
list(itertools.starmap(self._connect, info))
File "/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py", line 74, in _connect
s = socket.socket(af, socktype, proto)
File "/usr/lib64/python3.8/socket.py", line 231, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
OSError: [Errno 97] Address family not supported by protocol
/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py:107: UnexpectedException
________________________________________________________________________ [doctest] portend.occupied ________________________________________________________________________
132
133 Wait for the specified port to become occupied (accepting requests).
134 Return when the port is occupied or raise a Timeout if timeout has
135 elapsed.
136
137 Timeout may be specified in seconds or as a timedelta.
138 If timeout is None or ∞, the routine will run indefinitely.
139
140 >>> occupied('localhost', find_available_local_port(), .1)
Differences (unified diff with -expected +actual):
@@ -1,3 +1,14 @@
Traceback (most recent call last):
-...
-Timeout: Port ... not bound on localhost.
+ File "/usr/lib64/python3.8/doctest.py", line 1336, in __run
+ exec(compile(example.source, filename, "single",
+ File "<doctest portend.occupied[0]>", line 1, in <module>
+ occupied('localhost', find_available_local_port(), .1)
+ File "/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py", line 157, in occupied
+ Checker(timeout=0.5).assert_free(host, port)
+ File "/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py", line 71, in assert_free
+ list(itertools.starmap(self._connect, info))
+ File "/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py", line 74, in _connect
+ s = socket.socket(af, socktype, proto)
+ File "/usr/lib64/python3.8/socket.py", line 231, in __init__
+ _socket.socket.__init__(self, family, type, proto, fileno)
+OSError: [Errno 97] Address family not supported by protocol
/home/tkloczko/rpmbuild/BUILD/portend-3.1.0/portend.py:140: DocTestFailure
_____________________________________________________ TestChecker.test_check_port_nonlistening[AddressFamily.AF_INET6] _____________________________________________________
self = <test_portend.TestChecker object at 0x7f8ae2dff430>, nonlistening_addr = ('::', 56509, 0, 0)
def test_check_port_nonlistening(self, nonlistening_addr):
> portend.Checker().assert_free(nonlistening_addr)
test_portend.py:61:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
portend.py:71: in assert_free
list(itertools.starmap(self._connect, info))
portend.py:74: in _connect
s = socket.socket(af, socktype, proto)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, family = <AddressFamily.AF_INET6: 10>, type = <SocketKind.SOCK_STREAM: 1>, proto = 6
fileno = None
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
# For user code address family and type values are IntEnum members, but
# for the underlying _socket.socket they're just integers. The
# constructor of _socket.socket converts the given argument to an
# integer automatically.
if fileno is None:
if family == -1:
family = AF_INET
if type == -1:
type = SOCK_STREAM
if proto == -1:
proto = 0
> _socket.socket.__init__(self, family, type, proto, fileno)
E OSError: [Errno 97] Address family not supported by protocol
/usr/lib64/python3.8/socket.py:231: OSError
___________________________________________________ TestChecker.test_free_with_immediate_timeout[AddressFamily.AF_INET6] ___________________________________________________
self = <test_portend.TestChecker object at 0x7f8ae2dc5340>, nonlistening_addr = ('::', 56509, 0, 0), immediate_timeout = None
def test_free_with_immediate_timeout(self, nonlistening_addr, immediate_timeout):
host, port = nonlistening_addr[:2]
> portend.free(host, port, timeout=1.0)
test_portend.py:65:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
portend.py:122: in free
Checker(timeout=0.1).assert_free(host, port)
portend.py:71: in assert_free
list(itertools.starmap(self._connect, info))
portend.py:74: in _connect
s = socket.socket(af, socktype, proto)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, family = <AddressFamily.AF_INET6: 10>, type = <SocketKind.SOCK_STREAM: 1>, proto = 6
fileno = None
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
# For user code address family and type values are IntEnum members, but
# for the underlying _socket.socket they're just integers. The
# constructor of _socket.socket converts the given argument to an
# integer automatically.
if fileno is None:
if family == -1:
family = AF_INET
if type == -1:
type = SOCK_STREAM
if proto == -1:
proto = 0
> _socket.socket.__init__(self, family, type, proto, fileno)
E OSError: [Errno 97] Address family not supported by protocol
/usr/lib64/python3.8/socket.py:231: OSError
========================================================================= short test summary info ==========================================================================
ERROR test_portend.py::TestChecker::test_check_port_listening[AddressFamily.AF_INET6] - OSError: [Errno 97] Address family not supported by protocol
ERROR test_portend.py::TestChecker::test_free_with_timeout[AddressFamily.AF_INET6] - OSError: [Errno 97] Address family not supported by protocol
ERROR test_portend.py::TestChecker::test_occupied_with_immediate_timeout[AddressFamily.AF_INET6] - OSError: [Errno 97] Address family not supported by protocol
ERROR test_portend.py::test_main[AddressFamily.AF_INET6] - OSError: [Errno 97] Address family not supported by protocol
ERROR test_portend.py::test_main_timeout[AddressFamily.AF_INET6] - OSError: [Errno 97] Address family not supported by protocol
FAILED portend.py::portend.Checker.assert_free
FAILED portend.py::portend.free
FAILED portend.py::portend.occupied
FAILED test_portend.py::TestChecker::test_check_port_nonlistening[AddressFamily.AF_INET6] - OSError: [Errno 97] Address family not supported by protocol
FAILED test_portend.py::TestChecker::test_free_with_immediate_timeout[AddressFamily.AF_INET6] - OSError: [Errno 97] Address family not supported by protocol
================================================================== 5 failed, 10 passed, 5 errors in 0.93s ==================================================================
I am trying to install portend (python2-portend) on Arch Linux and am running into the following error:
Does this have to do with me using IPv4? I have tried to enable IPv6 and try again to no avail. IPv6 modules are enabled by default in linux, so I am not sure if this is something I am doing wrong or not.
While I appreciate the strong focus you have on testing and putting core functionality in core packages, I really wonder if in the case of tempora
for portend
this might be a bit overkill.
All you really use it for is to check if time_passed = time.now() - start_time
in the occupied
/free
checks.
Adding tempora
also ads it's (in this case unused) dependency pytz
.
Should super-simple Python-core functionality really require it's own package-dependency?
In portend.free
, if the full duration of the timeout elapses between L112 and L114, a Timeout
error will be thrown even if the port has been free the whole time. This can happen when debugging; you can reproduce it as follows on Python 3.7:
python -m pdb -c 'break portend.py:114' -c 'continue' -c 'import time; time.sleep(1.0)' -c 'continue' -c 'quit' -m portend --timeout=0.5 localhost:12345 free
I think I might have also observed it under other circumstances, but don't have a minimal repro to show at the moment. portend.occupied
has an analogous problem.
After adding support for Windows tests and enabling them in AppVeyor, it's clear that tests are failing. This issue is likely implicated in failure reported in cherrypy/cherrypy#1605.
A few months ago, the portend tests were passing, but today, the tests are failing. The tests still pass on my local system. The issue is likely a manifestation of travis-ci/travis-ci#8711, though I don't see the reported error message.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.