Py2exe and Multi Treading problem.

F

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. If I cal
CmdPortThread without Trading, It works perfect.
What did I miss here? My setup.py is standard without any include or
excludes. Should I include something in setup.py? I am not a py2exe
newbie but I'll appreciate detailed descriptions.
 
G

GHUM

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
 
F

Farsheed Ashouri

NO it dont work. If I remove threading part, it works like a charm.
Any Idea?
 
T

Thin Myrna

Farsheed said:
NO it dont work. If I remove threading part, it works like a charm.
Any Idea?

Of course it does then. Try to join the thread or do something else to
prevent the non-threading part to exit prematurely.

HTH
Thin
 
F

Farsheed Ashouri

Of course it does then. Try to join the thread or do something else to
prevent the non-threading part to exit prematurely.

HTH
Thin

Thanks, I got it. Very useful for me.
Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,518
Latest member
TobiasAxf

Latest Threads

Top