Py2exe and Multi Treading problem.

GHUM haraldarminmassa at gmail.com
Wed Mar 12 11:14:06 CET 2008


Farsheed Ashouri ,

> Here is my script
> #**********************************************************************
> #**********************************************************************
> import threading
> import socket
> def openSocket(portNum):
>     mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
>     mySocket.bind ( ( '', portNum ) )
>     mySocket.listen ( 1 )
>     channel, details = mySocket.accept()
>     msg = channel.recv(4096)
>
> class CmdPortThread( threading.Thread ):
>     def run( self ):
>         openSocket(6000)
>
> def fakeCommandPort():
>     CmdPortThread().start()
> fakeCommandPort()

> If works perfect with python 2.5.2. Now I want to convert it to
> standalone program.
> but the .exe file fails to run without any error.

are you sure that it fails to run? I expect it to run, and exit
immediately after fakeCommandPort(). That is: there is nothing more to
do in the main thread, so the application exits.

To learn more, add prints and use the usual if __name__=='__main__'

class CmdPortThread( threading.Thread ):
     def run( self ):
         print "Thread CmdPortThread running"
         openSocket(6000)

if __name__=='__main__':
    print "Mese running"
    fakeCommandPort()
    print "Mese done starting Thread"


Harald




More information about the Python-list mailing list