# Buggy code
def map_network(self, pool_size=255):
    """
    Maps the network
    :param pool_size: amount of parallel ping processes
    :return: list of valid ip addresses
    """
    if not self.ping:
        print(
            "Error: `ping` executable not found. Please enter the IP "
            "address in the text box manually"
        )
        return
    ip_list = list()

    # get my IP and compose a base like 192.168.1.xxx
    ip_parts = self.get_my_ip().split(".")
    base_ip = ip_parts[0] + "." + ip_parts[1] + "." + ip_parts[2] + "."

    # prepare the jobs queue
    try:
        jobs = multiprocessing.Queue()
        results = multiprocessing.Queue()

        pool = [
            multiprocessing.Process(target=self.pinger, args=(jobs, results))
            for _ in range(pool_size)
        ]
    except PermissionError:
        print(
            "The current system of packaging of guiscrcpy does not "
            "support semaphores. Therefore its not possible to "
            "multiprocess ip port scanning. Alternatively use `nmap` "
            "or `nutty` to scan your network."
        )
        return

    for p in pool:
        p.start()

    # cue hte ping processes
    for i in range(1, 255):
        jobs.put(base_ip + "{0}".format(i))

    for _ in pool:
        jobs.put(None)

    for p in pool:
        p.join()

    # collect he results
    while not results.empty():
        ip = results.get()
        ip_list.append(ip)

    return ip_list


# Traceback (OSError)
Process Process-232:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/process.py", line 99, in run
File "/usr/local/lib/python3.7/site-packages/guiscrcpy/network/network.py", line 27, in pinger
OSError: [Errno 24] Too many open files: '/dev/null'
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/guiscrcpy/ux/network.py", line 117, in refresh
self.listView.addItems(self.nm.map_network())
File "/usr/local/lib/python3.7/site-packages/guiscrcpy/network/network.py", line 88, in map_network
p.start()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/process.py", line 112, in start
self._popen = self._Popen(self)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/context.py", line 277, in _Popen
return Popen(process_obj)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/popen_fork.py", line 20, in __init__
self._launch(process_obj)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/popen_fork.py", line 69, in _launch
parent_r, child_w = os.pipe()
OSError: [Errno 24] Too many open files
Abort trap: 6

# Fixed code
def map_network(self, pool_size=255):
    """
    Maps the network
    :param pool_size: amount of parallel ping processes
    :return: list of valid ip addresses
    """
    ip_list = list()

    # get my IP and compose a base like 192.168.1.xxx
    ip_parts = self.get_my_ip().split(".")
    base_ip = ip_parts[0] + "." + ip_parts[1] + "." + ip_parts[2] + "."

    max_threads = 50

    def check_adb_port(ip):
        """
        Check if port is open
        :param ip:
        :param port:
        :return:
        """
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            socket.setdefaulttimeout(2.0)
            result = sock.connect_ex((ip, 5555))
            if result == 0:
                ip_list.append(ip)
            sock.close()
        except Exception as e:
            logging.warning("Unable to check %s: %s", ip, e)

    for i in range(1, 255):
        threading.Thread(
            target=check_adb_port,
            args=[f"{base_ip}{i}"],
        ).start()

    # limit the number of threads.
    while threading.active_count() > max_threads:
        time.sleep(1)

    return ip_list