This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JoshN
Recipients JoshN
Date 2016-04-06.18:07:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1459966025.84.0.875779742702.issue26703@psf.upfronthosting.co.za>
In-reply-to
Content
Creating a socket in one thread and sharing it with another will cause the socket to corrupt as soon as the thread it was created in exits.

Example code:
import socket, threading, time, os

def start():
    a = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    a.bind(("", 8080))
    a.set_inheritable(True)

    thread = threading.Thread(target=abc, args=(a.fileno(),))
    thread.start()

    time.sleep(2)
    print("Main thread exiting, socket is still valid: " + str(a) + "\n")

def abc(b):
    sock = socket.socket(fileno=b)
    for _ in range(3):
        print("Passed as an argument:" + str(sock) + "\n=====================")

        time.sleep(1.1)

start()

Note that, as soon as the main thread exits, the socket isn't closed, nor is the fd=-1, etc. Doing anything with this corrupted object throws WinError 10038 ('operation performed on something that is not a socket').

I should note that the main thread exiting doesn't seem to be the cause, it is the original object containing the socket going out of scope that causes the socket to become corrupted.

-JoshN
History
Date User Action Args
2016-04-06 18:07:05JoshNsetrecipients: + JoshN
2016-04-06 18:07:05JoshNsetmessageid: <1459966025.84.0.875779742702.issue26703@psf.upfronthosting.co.za>
2016-04-06 18:07:05JoshNlinkissue26703 messages
2016-04-06 18:07:05JoshNcreate