See lines 123-124:
https://github.com/jftuga/universe/blob/master/tcpscan.py
I have used this under Linux, OSX and Windows. It's cool to add the Thread Count field in Task Manager and then see something I wrote use so many threads! I am more of a sys admin, so this code could be better - but it seems to work very well. :-)