473,671 Members | 2,228 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using SimpleXMLRPCSer ver in a Windows Service

After some Googling I found a post of someone who wanted to do exactly
as what I want to do now.
There is however a problem in his code that makes the service fails
after the first connection. I slightly modified his code and now I can
run the service longer before I run into trouble.
I then tried making the SimpleXMLRPCSer ver multi-threaded, hoping the
problem would disappear, but no avail.
The code is as follows:
The commented part in the while loop is from the original code.
<CODE>
## XML-RPC Service
import sys
import win32serviceuti l
import win32service
import win32event
import win32evtlogutil
import win32file
import servicemanager
import SimpleXMLRPCSer ver
import SocketServer
import select

class OBJECT:
def hello(self, text):
return "Hello World (%s)" % text

class ThreadedSimpleX MLRPCServer(Soc ketServer.Threa dingMixIn,
SimpleXMLRPCSer ver.SimpleXMLRP CServer): pass

class XMLRPCSERVICE(w in32serviceutil .ServiceFramewo rk):
_svc_name_ = "XMLRPCSERV ICE"
_svc_display_na me_ = "XMLRPCSERV ICE"
_svc_descriptio n_ = "XMLRPCSERV ICE"

def __init__(self, args):
win32evtlogutil .AddSourceToReg istry(self._svc _display_name_,
sys.executable, "Applicatio n")
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)

self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)
self.hSockEvent = win32event.Crea teEvent(None, 0, 0, None)
self.stop_reque sted = 0

def SvcStop(self):
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
self.stop_reque sted = 1
win32event.SetE vent(self.hWait Stop)

def SvcDoRun(self):
## Write a started event
servicemanager. LogMsg(
servicemanager. EVENTLOG_INFORM ATION_TYPE,
servicemanager. PYS_SERVICE_STA RTED,
(self._svc_name _, ' (%s)' % self._svc_name_ ))

server = ThreadedSimpleX MLRPCServer(("" , 8080))
object = OBJECT()
server.register _instance(objec t)
self.socket = server.socket

while 1:
r, w, x = select.select([self.socket],[],[],10)
if r == [self.socket]:
server.handle_r equest()
if self.stop_reque sted:
self.socket.clo se()
break
#win32file.WSAE ventSelect(serv er,
self.hSockEvent ,win32file.FD_A CCEPT)
#rc =
win32event.Wait ForMultipleObje cts((self.hWait Stop,self.hSock Event), 0,
win32event.INFI NITE)
#if rc == win32event.WAIT _OBJECT_0:
# break
#else:
# server.handle_r equest()
# win32file.WSAEv entSelect(serve r,self.hSockEve nt, 0)
# #server.serve_f orever() ## Works, but breaks the

## Write a stopped event
win32evtlogutil .ReportEvent(se lf._svc_name_,
servicemanager. PYS_SERVICE_STO PPED,0,
servicemanager. EVENTLOG_INFORM ATION_TYPE,
(self._svc_name _,""))

if __name__ == '__main__':
win32serviceuti l.HandleCommand Line(XMLRPCSERV ICE)
</CODE>

I tested with the following:

<CODE>

import xmlrpclib
import time

server = xmlrpclib.Serve rProxy("http://localhost:8080" )
for i in range(100):
print server.hello("% d" % i)
time.sleep(1)

</CODE>

The loop ends with the following error:

<OUTPUT>
Hello World (0)
....
Hello World (44)
Traceback (most recent call last):
File "C:\Python24\Li b\site-packages\python win\pywin\frame work\scriptutil s.py",
line 310, in RunScript
exec codeObject in __main__.__dict __
File "C:\DATA\TestSo ap.py", line 6, in ?
print server.hello("% d" % i)
File "C:\Python24\li b\xmlrpclib.py" , line 1096, in __call__
return self.__send(sel f.__name, args)
File "C:\Python24\li b\xmlrpclib.py" , line 1383, in __request
verbose=self.__ verbose
File "C:\Python24\li b\xmlrpclib.py" , line 1137, in request
headers
ProtocolError: <ProtocolErro r for localhost:8080/RPC2: -1 >
</OUTPUT>

Can someone help me in creating a windows service that allows me to
handle XMLRPC request?

Thanks in advance,

Rudy Schockaert
Nov 23 '06 #1
0 1411

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4795
by: Marco Aschwanden | last post by:
I would like to develop a server based on python's xmlrpc. But I realized that SimpleXMLRPCServer does not spawn a thread for each request. How could the SimpleXMLRPCServer be turned into a multi-threaded Server? Is there a reason why the SimpleXMLRPCServer is not multi-threaded? Is there a plan to make it multi-threaded? Thanks for any hints in advance,
3
3820
by: Maxim Khesin | last post by:
Hi, the typical usage of SimpleXMLRPCServer registers some class with the server instance and then jumps into a serve-forever loop, e.g. server = SimpleXMLRPCServer(('', 8000)) server.register_instance(MyClass()) server.serve_forever() is there a way to process actions other than XML-RPC
0
1278
by: danu kusmana | last post by:
Hi Im trying to figure out why the same server script I use is running slower in Windows than in Linux. ServerTest.py: #! /usr/bin/env python import SocketServer
4
2335
by: codecraig | last post by:
Hi, I thought I posted this, but its been about 10min and hasnt shown up on the group. Basically I created a SimpleXMLRPCServer and when one of its methods gets called and it returns a response to the client, the server prints some info out to the console, such as, localhost - - "POST /RPC2 HTTP/1.0" 200 - Anyhow, is there a way I can surpress that so its not printed to the
0
1183
by: Thomas G. Apostolou | last post by:
Hello all, I use Python 2.3.3 and try to patch SimpleXMLRPCServer.py with the patch i got from Python.org. so after changing to the directory where both SimpleXMLRPCServer.py and SimpleXMLRPCServer.patch reside i run : patch -i SimpleXMLRPCServer.patch -b --verbose --dry-run SimpleXMLRPCServer.py and i get : Hmm...patch: **** unexpected end of hunk at line 47
0
1994
by: JDF | last post by:
I am trying to create a Windows service using SimpleXMLRPCServer and win32serviceutil. The service itself seems to be working properly (starts, stops, etc) and I can connect using an XMLRPC client from the localhost. However when I connect from a remote client, I either get a socket error or an xmlrpclib.ProtocolError error. If I use serve_forever() rather than handle_request(), the remote clients can connect but it breaks the Windows...
0
1218
by: Juju | last post by:
Hi, First, sorry for my poor English ! I used the SimpleXMLRPCServer facility of Python to develop a multithread-server, here's part of my code : -- class TotoSimpleXMLRPCServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
3
7239
by: Achim Domma | last post by:
Hi, is SimpleXMLRPCServer multithreaded or how does it handle multiple clients? I want to implement a simple server which will be queried by multiple processes for work to be done. The server will simply hold a queue with files to process. The clients will ask for the next file. Do I have to sync access to the queue or is the server not threaded at all? regards,
9
3272
by: Bret | last post by:
I'm coming back to Python after an absence and it's surprising how many things I've forgotten since wandering (against my will) into Java land. Anyway, I have a need for a way to make SimpleXMLRPCServer interruptable. Basically, I have a main server that, in response to certain RPC calls, creates additional servers on different ports. I then need to be able to shut these additional servers down. I've got something like this in the...
0
8473
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8911
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.