Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78292 > unrolled thread
| Started by | "Arulnambi Nandagoban" <a.nandagoban@traxens.com> |
|---|---|
| First post | 2014-09-24 16:49 +0200 |
| Last post | 2014-09-24 16:49 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
RE: Python as Windows Service "Arulnambi Nandagoban" <a.nandagoban@traxens.com> - 2014-09-24 16:49 +0200
| From | "Arulnambi Nandagoban" <a.nandagoban@traxens.com> |
|---|---|
| Date | 2014-09-24 16:49 +0200 |
| Subject | RE: Python as Windows Service |
| Message-ID | <mailman.14317.1411570176.18130.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
De : Gmail [mailto:mrjean1@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" <a.nandagoban@traxens.com> wrote:
De : MrJean1 [mailto:mrjean1@gmail.com]
Envoyé : Tuesday, September 23, 2014 5:55 PM
À : a.nandagoban@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
Back to top | Article view | comp.lang.python
csiph-web