I'm trying to write a python module for SET and after some testing I found the following issue:
I have a module that spawns a Thread for handling output from a subprocess that is called as soon as the thread starts, much like this:
#SET imports here
from threading import *
from subprocess import *

class T(Thread):
        def __init__(self):
                super(T, self).__init__()

        def run(self):
                cmd = ["hostapd", "path_to_my_conf"]
                self.p = Popen(cmd, stdout = PIPE)

def main():
        print("instantiate and start thread")
        t = T()
        print("thread started, wait for string 'gone'!")

My real code starts hostapd, but this is not so important, any process that does not terminate is good to show the issue (i.e. I tested it with top and it's the same).
The problem is: the code executes, fork, call Popen but Popen seems to deadlock (print "gone" is never executed)

Can someone confirm this issue? I'm running python 2.6.5 gcc 4.4.3 BT5 R2 (kernel 3.2.6)

After some research I noticed more:
Popen finishes execution (and print "gone" is executed) as soon as the module terminates and execution flow returns to SET main script (/pentest/exploits/set/set line 141 -142 in SET v3.2.2)
# third party modules
if main_menu_choice == '3':				
	try: reload(src.core.module_handler)
	except: import src.core.module_handler
Then I did some mods to the code to see what caused the problem and I found the following:
if you wrap the src.core.module_handler code into a function (say HandleModules() ) and call it this way
# third party modules
if main_menu_choice == '3':				
	#just test code, forget about reload() for now
        from src.core.module_handler_modified import HandleModules
everything goes on well without blocking.

Actually this seems more a python problem than a SET bug, but I'd like to hear some opinions from you.
The solution to my problem is pretty simple, just call Popen before starting thread, but this is not the point, I'd like to understand why my script behaves this strange way!!

Tank you all for support,