473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

medusa as win32 service

I wonder if this is the right way to write a medusa(asyncore) server
with the win32all framework. Other example services seem to create an
event to pass the stop signal from SvcStop into a separate termination
method, but I'm unsure how that would mix with the polling loop.

This simple framework seems to start and stop OK, but I wonder if I'm
missing some obvious race or something.

import win32serviceutil, win32service,
class MeducaService(win32serviceutil.ServiceFramework):
_svc_name_ = "MedusaService"
_svc_display_name_ = "Medusa Service"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP _PENDING)
print "Received Quit from Win32"
socket_map = asyncore.socket_map
while socket_map:
k, v = socket_map.popitem()
try:
print "Shutting down",k,v
v.close()
except:
pass
del k, v

def SvcDoRun(self):
start_medusa()

--
Robin Becker
Jul 18 '05 #1
7 2748
Hi,

Before I start the trial & error -cycle,
has anybody tried to start Bash -shell
script in Cygwin environment
from Python running in W2K?

True, Cygwin has Python package available, but I would like to
use true W2K version of Python. This would be the first
step of gradual conversion of all the shell scripts in Cygwin
to true W2K Python scripts: I would initially have WxPython Menu
in W2K from which I start Cygwin scripts.

-pekka-

Jul 18 '05 #2
Robin Becker wrote:
I wonder if this is the right way to write a medusa(asyncore) server
with the win32all framework. Other example services seem to create an
event to pass the stop signal from SvcStop into a separate termination
method, but I'm unsure how that would mix with the polling loop.

This simple framework seems to start and stop OK, but I wonder if I'm
missing some obvious race or something.


SvcStop will be called on a different thread. I don't know enough about
socket semantics to know if this is an issue.

When I've tried to play with async based services, IIRC there were a few
problems if a connection existed at shutdown time. If "close" could
ever block, then Windows would get quite upset. If a "close()" ever
fails, then I guess there is a risk that the main loop will not
terminate, again making Windows upset. But as above, I don't know
enough about the framework to comment on the risks here.

So really, the issues are all Python related - the win32 interactions
appear OK, assuming close could never block.

For the SpamBayes project, our framework needed a "clean shutdown" to
save our databases etc, so we ended up using urlopen to connect to a
special "shutdown" URL. I didn't write that part, so I don't understand
if there was a better option.

Hope this helps a little :)

Mark.

Jul 18 '05 #3
Robin Becker <ro***@jessikat.fsnet.co.uk> wrote in message news:<Wn**************@jessikat.fsnet.co.uk>...
I wonder if this is the right way to write a medusa(asyncore) server
with the win32all framework. Other example services seem to create an
event to pass the stop signal from SvcStop into a separate termination
method, but I'm unsure how that would mix with the polling loop.

This simple framework seems to start and stop OK, but I wonder if I'm
missing some obvious race or something.


I think the cleanest design for this is to use the
medusa.threading.select_trigger function to send an asyncore.ExitNow
exception into the main select loop. The only problem with this is
that the current medusa.threading.select_trigger (in the sourceforge
medusa version) catches (and does not re-raise) this exception. I've
modified our code so that it does not catch it and this seems to work
very well (we have a web server using medusa that runs as a service).

Regards,
Giles Brown
Jul 18 '05 #4
In article <bq***********@arachne.labyrinth.net.au>, Mark Hammond
<mh******@skippinet.com.au> writes
Robin Becker wrote:
I wonder if this is the right way to write a medusa(asyncore) server
with the win32all framework. Other example services seem to create an
event to pass the stop signal from SvcStop into a separate termination
method, but I'm unsure how that would mix with the polling loop.

This simple framework seems to start and stop OK, but I wonder if I'm
missing some obvious race or something.
SvcStop will be called on a different thread. I don't know enough about
socket semantics to know if this is an issue.

When I've tried to play with async based services, IIRC there were a few
problems if a connection existed at shutdown time. If "close" could
ever block, then Windows would get quite upset. If a "close()" ever
fails, then I guess there is a risk that the main loop will not
terminate, again making Windows upset. But as above, I don't know
enough about the framework to comment on the risks here.

So really, the issues are all Python related - the win32 interactions
appear OK, assuming close could never block.

For the SpamBayes project, our framework needed a "clean shutdown" to
save our databases etc, so we ended up using urlopen to connect to a
special "shutdown" URL. I didn't write that part, so I don't understand
if there was a better option.

Hope this helps a little :)

it does indeed as I'm then into ensuring that the close methods are
reasonable. So I guess the problem reduces to whether the simple medusa
services ftp/http are cleanly terminatable.

As a matter of interest how does one get rid of LEGACY services? Whilst
getting the above going I seem to have created a LEGACY_MEDUSASERVICE in
the registry. All attempts at deletion fail.
Mark.


--
Robin Becker
Jul 18 '05 #5
In article <57**************************@posting.google.com >, Giles
Brown <gi*********@hotmail.com> writes
Robin Becker <ro***@jessikat.fsnet.co.uk> wrote in message news:<WnWU+VAnDjy$EwE
P@jessikat.fsnet.co.uk>...
I wonder if this is the right way to write a medusa(asyncore) server
with the win32all framework. Other example services seem to create an
event to pass the stop signal from SvcStop into a separate termination
method, but I'm unsure how that would mix with the polling loop.

This simple framework seems to start and stop OK, but I wonder if I'm
missing some obvious race or something.


I think the cleanest design for this is to use the
medusa.threading.select_trigger function to send an asyncore.ExitNow
exception into the main select loop. The only problem with this is
that the current medusa.threading.select_trigger (in the sourceforge
medusa version) catches (and does not re-raise) this exception. I've
modified our code so that it does not catch it and this seems to work
very well (we have a web server using medusa that runs as a service).

Regards,
Giles Brown

well it is an opensource project, so perhaps you could submit patches.
I'm not sure how much work A Kuchling would/could devote to it. I also
have made some relatively trivial changes to the status extension, but
they don't affect very much.
--
Robin Becker
Jul 18 '05 #6
Pekka,

On Sun, Nov 30, 2003 at 09:12:12PM +0200, Pekka Niiranen wrote:
Before I start the trial & error -cycle, has anybody tried to start
Bash -shell script in Cygwin environment from Python running in W2K?


Something like the following should meet your needs:

Python ... [MSC 32 bit (Intel)] on win32
import os
os.system('bash ~/bin/foo.sh')

foo
0

Jason

--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6

Jul 18 '05 #7
I have used w32python interactively from a cygwin bash. its okay.
but I think I remember that the python environment (syspath?) was not
set properly. so, this would be something to check in your cygwin
bash rc file..

--
David Bear
phone: 480-965-8257
fax: 480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
"Beware the IP portfolio, everyone will be suspect of trespassing"
Jul 18 '05 #8

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

Similar topics

0
by: Brad Clements | last post by:
I need to get my cross platform medusa based package to support SSL on Windows and Linux. Using Python 2.3, there doesn't seem to be any way to do this on Windows without M2Crypto. Is that...
11
by: mir nazim | last post by:
hi, i m planning to start writing intranet applications and want ur real cool advices for choosing the correct platform. the choice is between the three: 1. Twisted 2. Medusa 3. Zope (i do...
0
by: Tom Brown | last post by:
Hi, I created a win32 service for XPPro called N4010ATestService.py (see below). The service runs as a particular user with administrative rights. It starts a thread that creates a simple socket...
6
by: Laszlo Zsolt Nagy | last post by:
Sorry, I realized that the import zlib was not executed from my (working) service. So here is the question: why can't I use zlib from a win32 service? Is there any way to make it working? ...
8
by: dthom | last post by:
Hi, I have a C# service application - and a Win32 / C++ service application running on my system. I need someway to interact between those two - the Win32 application is pure Win32 - so im...
9
by: esafran | last post by:
Hi, I've have encountered a very strange behaviour under C#. My application is registering for: Microsoft.Win32.SystemEvents.DisplaySettingsChanged &...
0
by: Graeme Matthew | last post by:
Hi all does anyone know where you can find examples of how to write a native python webserver, I have looked at medusa and asyncore but there are no real examples and the doco is very light ...
2
by: Gregor Mosheh | last post by:
I'm trying to write a Win32 service. The following is straight from Python Programming on Win32 and it doesn't work. Is that book out of date; is there a new way to do services? I searched Google...
0
by: jbenezech | last post by:
Hi all , I have a perl/java app running under Win32. The application consists of a perl service (Win32::Daemon) and of java classes. The perl service calls every xx hours java classes to perform...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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,...

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.