Re: Python as Windows Service

2014-09-25 Thread Zachary Ware
On Thu, Sep 25, 2014 at 9:33 AM, Nagy László Zsolt  wrote:
> By the way, do we have support for creating a Windows Service for Python 3
> already? I know it was not working about 6 months ago. Does pywin32
> (PythonService.exe ?) still lack this feautue?

I can confirm that a Windows service can be created using the latest
py2exe (which supports Python 3.3+) with Python 3.4 and pywin32 build
219.  I assume that pythonservice.exe would also work, but I haven't
tried it on its own.

-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python as Windows Service

2014-09-25 Thread Nagy László Zsolt



*De :*Gmail [mailto:mrje...@gmail.com]
*Envoyé :* Wednesday, September 24, 2014 2:41 PM
*À :* Arulnambi Nandagoban
*Objet :* Re: Python as Windows Service

Also, this may work for you

<http://nssm.cc/description>

<http://nssm.cc/usage>

NSSM installs an existing app as a service.


//Jean/



By the way, do we have support for creating a Windows Service for Python 
3 already? I know it was not working about 6 months ago. Does pywin32 
(PythonService.exe ?) still lack this feautue?


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Python as Windows Service

2014-09-24 Thread Arulnambi Nandagoban
De : Gmail [mailto:mrje...@gmail.com] 
Envoyé : Wednesday, September 24, 2014 2:41 PM
À : Arulnambi Nandagoban
Objet : Re: Python as Windows Service

 

Also, this may work for you

 

<http://nssm.cc/description>

<http://nssm.cc/usage>

 

NSSM installs an existing app as a service.


/Jean

 


On Sep 24, 2014, at 3:16 AM, "Arulnambi Nandagoban"  
wrote:

De : MrJean1 [mailto:mrje...@gmail.com] 
Envoyé : Tuesday, September 23, 2014 5:55 PM
À : a.nandago...@traxens.com
Objet : Python as Windows Service

 

Here's one, simple example

 

<http://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how>

There are more, just search for "Python Windows Service" for example.


/Jean

 

 

Thank you !!! 

 

--

Nambi

 

 

Thank you again !!!

 

I managed to run the server as as service with help of sample code provided in 
<http://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how
 .

I found some problem in stopping the service.  I feel it because of 
socket.accept() which blocks. This the class where I implemented the server in 
the main method.

 

 

class TraxServerSvc (win32serviceutil.ServiceFramework):

_svc_name_ = "Testserver"

_svc_display_name_ = "Pytestserver"

 

def __init__(self,args):


win32serviceutil.ServiceFramework.__init__(self,args)

self.hWaitStop = 
win32event.CreateEvent(None,0,0,None)

self.sloop = True

self.serversock = 0

 

def SvcStop(self):


self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)   

win32event.SetEvent(self.hWaitStop)

self.sloop = False

 

def SvcDoRun(self):


servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, 
servicemanager.PYS_SERVICE_STARTED, (self._svc_name_,''))

self.main()



def main(self):

self.serversock = socket.socket(socket.AF_INET, 
socket.SOCK_STREAM)

self.serversock.bind(server_config())

self.serversock.listen(5)   


while 
(win32event.WaitForSingleObject(self.hWaitStop, 0) == 258): 
   

try:

clientsock, 
addr = self.serversock.accept()


Pysconfig.logger.info('...connected from: %s', addr) # logging


thread.start_new_thread(handler, (clientsock, addr))


Pysconfig.logger.info('Thread ID: %s', thread.get_ident()) # logging
  

except socket.error, msg:


Pysconfig.logger.info('Failed to create socket. Error code: ' + str(msg[0]) + ' 
, Error message : ' + msg[1])

pass

self.serversock.shutdown(socket.SHUT_RDWR)

self.serversock.close()


servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, 
servicemanager.PYS_SERVICE_STOPPED, (self._svc_name_,''))

 

if __name__ == '__main__':

win32serviceutil.HandleCommandLine(TraxServerSvc)

 

When win32event.WaitForSingleObject(self.hWaitStop, 0) method returns zero , I 
need to quit the while loop to stop the service. But in the above case, since 
it blocks in accept , I need to make connection from client to completely stop 
service. 

 

--

nambi

 

 

 

 

 

 

-- 
https://mail.python.org/mailman/listinfo/python-list