(Python) how to tell if server listens on a port in use

236 views
Skip to first unread message

sp...@rigetti.com

unread,
Jun 2, 2017, 3:12:24 PM6/2/17
to grpc.io
In Python, how can find out if the port I'm trying to use for my gRPC server is already in use?  I need to add the port before starting the server, but if I add a port already in use, it starts without any errors.

I'm running Python 2.7 on CentOS 7.

Nathaniel Manista

unread,
Jun 2, 2017, 5:15:17 PM6/2/17
to sp...@rigetti.com, grpc.io
On Fri, Jun 2, 2017 at 12:12 PM, <sp...@rigetti.com> wrote:
In Python, how can find out if the port I'm trying to use for my gRPC server is already in use? I need to add the port before starting the server, but if I add a port already in use, it starts without any errors.

I'm running Python 2.7 on CentOS 7.

I've confirmed your observation.

Did you see any error logging? Possibly something like '"description":"No address added out of total 1 resolved"'?


Thanks for the report,
-Nathaniel

Nathaniel Manista

unread,
Jun 2, 2017, 6:21:04 PM6/2/17
to Spike Curtis, grp...@googlegroups.com
+support list (please retain so that everyone can learn from the conversation)

On Fri, Jun 2, 2017 at 3:01 PM, Spike Curtis <sp...@rigetti.com> wrote:
It doesn't seem to drop any errors.

With the current version, can I do something like?

result = sever.add_secure_port(...)
if result == 0:
    raise PortInUseError()

I haven't yet confirmed this myself but yes, I believe this will work as you need it to work.
-N
Reply all
Reply to author
Forward
0 new messages