Skip to content

Commit

Permalink
migrate deprecated connections to net_connections (#3641)
Browse files Browse the repository at this point in the history
* migrate deprecated connections to net_connections

* check for psutil version
  • Loading branch information
benedikt-bartscher authored and Alek Petuskey committed Jul 15, 2024
1 parent 845c02c commit 42f18b8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions reflex/utils/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import collections
import contextlib
import importlib.metadata
import os
import signal
import subprocess
Expand Down Expand Up @@ -58,8 +59,12 @@ def get_process_on_port(port) -> Optional[psutil.Process]:
"""
for proc in psutil.process_iter(["pid", "name", "cmdline"]):
try:
for conns in proc.connections(kind="inet"):
if conns.laddr.port == int(port):
if importlib.metadata.version("psutil") >= "6.0.0":
conns = proc.net_connections(kind="inet") # type: ignore
else:
conns = proc.connections(kind="inet")
for conn in conns:
if conn.laddr.port == int(port):
return proc
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
Expand Down

0 comments on commit 42f18b8

Please sign in to comment.