[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Py2exe and Multi Treading problem.

farsheed

3/12/2008 1:56:00 AM

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.
4 Answers

GHUM

3/12/2008 10:14:00 AM

0

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

farsheed

3/12/2008 4:35:00 PM

0

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

Thin Myrna

3/12/2008 7:35:00 PM

0

Farsheed Ashouri wrote:
> 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

farsheed

3/17/2008 5:27:00 AM

0

On Mar 12, 10:35 pm, Thin Myrna <spamhater@spamhaters> wrote:
> Farsheed Ashouri wrote:
> > 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

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