[Python] Threading has no attribute Thread, no files named threading.py

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm coding a simple client/server setup. The server seems to start fine, but when I try to connect the client I get a message saying "Threading has no attribute Thread." Then the server stops.

    The only suggestion I've found doesn't work for me ... I have no files named threading.py, and the print(threading.__file__) statement shows the correct file path for the threading module.

    I've left out functions that don't use the threading module for this example.

    import socket
    import threading
    print(threading.__file__)

    HEADER = 64
    PORT = 5050
    SERVER = socket.gethostbyname(socket.gethostname())
    ADDR = (SERVER, PORT)
    FORMAT = "utf-8"
    DISCONNECT_MESSAGE = "!"

    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.bind(ADDR)

    ...

    def start():
    # Listen for and accept connections
    server.listen()
    print(f"[LISTENING] Server is listening on {SERVER}")
    while True:
    conn, addr = server.accept()
    t = threading.thread(target=handle_client, args=(conn, addr))
    t.start()
    print(f'[ACTIVE CONNECTIONS] {threading.activeCount() - 1}')

    print('Server is starting ...')
    start()

    Continue reading...

Compartilhe esta Página