# Buggy code
def attach(self, laddr: Union[str, Tuple]) -> None:
    """Attaches to an already running RPC client subprocess.

    Args:
        laddr: Address that the client is listening at. Can be supplied as a
               string "http://127.0.0.1:8545" or tuple ("127.0.0.1", 8545)"""
    if self.is_active():
        raise SystemError("RPC is already active.")
    if isinstance(laddr, str):
        o = urlparse(laddr)
        if not o.port:
            raise ValueError("No RPC port given")
        laddr = (o.hostname, o.port)
    try:
        proc = next(i for i in psutil.net_connections() if i.laddr == laddr)
    except StopIteration:
        raise ProcessLookupError("Could not find RPC process.")
    self._rpc = psutil.Process(proc.pid)
    if web3.provider:
        self._reset_id = self._snap()
    _notify_registry(0)


# Traceback (PermissionError)
Brownie v1.1.0 - Python development framework for Ethereum

Brownie project has been compiled at /Users/alper/eBlocBroker/contract/build/contracts
==================================================================== test session starts =====================================================================
platform darwin -- Python 3.7.5, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
rootdir: /Users/alper/eBlocBroker
plugins: eth-brownie-1.1.0, web3-5.0.0
collected 6 items
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/psutil-5.6.3-py3.7-macosx-10.13-x86_64.egg/psutil/_psosx.py", line 339, in wrapper
INTERNALERROR>     return fun(self, *args, **kwargs)
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/psutil-5.6.3-py3.7-macosx-10.13-x86_64.egg/psutil/_psosx.py", line 528, in connections
INTERNALERROR>     rawlist = cext.proc_connections(self.pid, families, types)
INTERNALERROR> PermissionError: [Errno 1] Operation not permitted
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/pytest-5.0.1-py3.7.egg/_pytest/main.py", line 213, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/pytest-5.0.1-py3.7.egg/_pytest/main.py", line 257, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/pluggy-0.12.0-py3.7.egg/pluggy/hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/pluggy-0.12.0-py3.7.egg/pluggy/manager.py", line 87, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/pluggy-0.12.0-py3.7.egg/pluggy/manager.py", line 81, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/pluggy-0.12.0-py3.7.egg/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/pluggy-0.12.0-py3.7.egg/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/pluggy-0.12.0-py3.7.egg/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/brownie/test/plugin.py", line 131, in pytest_runtestloop
INTERNALERROR>     brownie.network.connect(ARGV["network"])
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/brownie/network/main.py", line 41, in connect
INTERNALERROR>     rpc.attach(host)
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/brownie/network/rpc.py", line 109, in attach
INTERNALERROR>     proc = next(i for i in psutil.net_connections() if i.laddr == laddr)
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/psutil-5.6.3-py3.7-macosx-10.13-x86_64.egg/psutil/__init__.py", line 2263, in net_connections
INTERNALERROR>     return _psplatform.net_connections(kind)
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/psutil-5.6.3-py3.7-macosx-10.13-x86_64.egg/psutil/_psosx.py", line 252, in net_connections
INTERNALERROR>     cons = Process(pid).connections(kind)
INTERNALERROR>   File "/Users/alper/v/lib/python3.7/site-packages/psutil-5.6.3-py3.7-macosx-10.13-x86_64.egg/psutil/_psosx.py", line 344, in wrapper
INTERNALERROR>     raise AccessDenied(self.pid, self._name)
INTERNALERROR> psutil.AccessDenied: psutil.AccessDenied (pid=28029)

================================================================ no tests ran in 0.10 seconds ================================================================

# Fixed code
def attach(self, laddr: Union[str, Tuple]) -> None:
    """Attaches to an already running RPC client subprocess.

    Args:
        laddr: Address that the client is listening at. Can be supplied as a
               string "http://127.0.0.1:8545" or tuple ("127.0.0.1", 8545)"""
    if self.is_active():
        raise SystemError("RPC is already active.")
    if isinstance(laddr, str):
        o = urlparse(laddr)
        if not o.port:
            raise ValueError("No RPC port given")
        laddr = (o.hostname, o.port)
    try:
        proc = next(i for i in psutil.process_iter() if _check_connections(i, laddr))
    except StopIteration:
        raise ProcessLookupError("Could not find RPC process.")
    print(f"Attached to local RPC client listening at '{laddr[0]}:{laddr[1]}'...")
    self._rpc = psutil.Process(proc.pid)
    if web3.provider:
        self._reset_id = self._snap()
    _notify_registry(0)