Windows service in production?
Anyone know of a Python application running as a Windows service in production? I'm planning a network monitoring application that runs as a service and reports back to the central server. Sort of a heartbeat type agent to assist with "this server is down, go check on it" type situations. If using Visual Studio and C# is the more reliable way, then I'll go that route. I love Python, but everything I read about Python services seems to have workarounds ahoy for various situations (or maybe that's just Windows services in general?). And there seem to be multiple layers of workarounds, since it takes py2exe (or similar) and there are numerous workarounds required there, depending on which libraries and functionality are being used. Overall, reading about Windows services in Python is not exactly a confidence inspiring experience. If I knew of a reference example of something reliably running in production, I'd feel better than copying and pasting some code from a guy's blog. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows service in production?
On Aug 16, 2:52 am, Tim Golden wrote: > On 16/08/2011 05:32, snorble wrote: > > > Anyone know of a Python application running as a Windows service in > > production? I'm planning a network monitoring application that runs as > > a service and reports back to the central server. Sort of a heartbeat > > type agent to assist with "this server is down, go check on it" type > > situations. > > Don't know what it'll take to inspire you with confidence, but I have > several Python services running here without a hitch. > The longest have been running for about three years -- not without > a stop, since they have to be restarted for reasons external to the > service itself. > > There's no py2exe involved, just the pywin32 service wrappers. (The > apps in question are also set up to run standalone for testing etc.). > They're mostly around a helpdesk system: one app ingests email requests > to the helpdesk; another post-processes call changes, currently to > send out email alerts to interested parties; another triggers alarms > on calls for various purposes, etc. > > I don't claim they're the most sophisticated pieces of code on Earth, > but it doesn't sound like you're after anything spectacular either. > > TJG Interesting. Normally I would use py2exe then do "myapp.exe -install" to install the app as a service. How do you handle installing the service? Also what does the service show under the properties, for the executable? "python.exe script.py" or something else? -- http://mail.python.org/mailman/listinfo/python-list
Development tools and practices for Pythonistas
I'm not a Pythonista, but I aspire to be. My current tools: Python, gvim, OS file system My current practices: When I write a Python app, I have several unorganized scripts in a directory (usually with several named test1.py, test2.py, etc., from random ideas I have tested), and maybe a todo.txt file. Then I hack away, adding features in a semi-random order. Then I get busy with other things. Maybe one week I spend 20 hours on development. The next week, no time on development. A few weeks later when I have some time, I'm excited to get back to making progress, only to find that I have to spend 30-60 minutes figuring out where I left off. The code is usually out of sync with todo.txt. I see people who release new versions and bug fixes, so I sometimes will create a new directory and continue working from that copy, because it seems like the thing to do. But if I ever made something worth releasing, and got a request like, "I have problems with the 2.0 version. Can you send me the old 1.1 version?" I'd be like, "uhhh... let me hunt through my files by hand and get back to you in a month". I'm thinking I can do a lot better than this. I am aware of tools like version control systems, bug trackers, and things like these, but I'm not really sure if I need them, or how to use them properly. I think having some organization to all of this would help me to make more consistent progress, and spend less time bringing myself up to speed after some time off. I really like the idea of having a list of features, and tackling those features one at a time. I read about people who do this, and each new features gets a new minor version number. It sounds very organized and clean. But I'm not really sure of the best way to achieve this. Mainly I think I just need some recommendations to help create a good mental map of what needs to happen, and mapping jargon to concepts. Like, "each feature gets its own directory". Or with a version control tool, I don't know if a feature maps to a branch, or a commit? I appreciate any advice or guidance anyone has to offer. -- http://mail.python.org/mailman/listinfo/python-list
Monitoring/inventory client-server app
I'm writing a tool for monitoring the workstations and servers in our office. I plan to have a server and a client service that runs on each workstation and reports back to the server (heartbeat, disk free space, etc). So far I am considering XMLRPC, or a client service that just downloads a Python file and runs it. With XMLRPC I don't know how to easily add features without having to update every client. Also while playing with XMLRPC I learned that when you run a registered function, it runs it on the server. I was hoping it would run on the client, so that when I get the machine's computer name (or disk space, etc) it will return the client's info. It seems with XMLRPC I would have to hard code the functionality into the client (i.e. client gets it's computer name, then calls the XMLRPC function to pass it to the server)? I was hoping it would work more like, "pass some code to the client to be run on the client, and report it to the server". Almost XMLRPC in the reverse direction. With the download-and-run approach, it seems trivially easy to add new functionality to the clients. Just save the updated Python file to the server, and clients download it and run it. Are there any standard approaches to problems like this that can be recommended? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Monitoring/inventory client-server app
On Nov 17, 4:31 pm, Irmen de Jong wrote: > On 17-11-2011 5:17, snorble wrote: > > > > > > > > > > > I'm writing a tool for monitoring the workstations and servers in our > > office. I plan to have a server and a client service that runs on each > > workstation and reports back to the server (heartbeat, disk free > > space, etc). > > > So far I am considering XMLRPC, or a client service that just > > downloads a Python file and runs it. > > > With XMLRPC I don't know how to easily add features without having to > > update every client. Also while playing with XMLRPC I learned that > > when you run a registered function, it runs it on the server. I was > > hoping it would run on the client, so that when I get the machine's > > computer name (or disk space, etc) it will return the client's info. > > It seems with XMLRPC I would have to hard code the functionality into > > the client (i.e. client gets it's computer name, then calls the XMLRPC > > function to pass it to the server)? I was hoping it would work more > > like, "pass some code to the client to be run on the client, and > > report it to the server". Almost XMLRPC in the reverse direction. > > > With the download-and-run approach, it seems trivially easy to add new > > functionality to the clients. Just save the updated Python file to the > > server, and clients download it and run it. > > > Are there any standard approaches to problems like this that can be > > recommended? Thank you. > > The security implications are HUGE when you are thinking about > transferring and executing arbitrary code over the network. Avoid this > if at all possible. But if you can be 100% sure it's only trusted stuff, > things are not so grim. > > Have a look at Pyro, or even Pyro Flame: > > http://packages.python.org/Pyro4/http://packages.python.org/Pyro4/flame.html > > Flame allows for very easy remote module execution and a limited way of > transferring code to the 'other side'. > > Also what is wrong with running an XMLrpc server, or Pyro daemon, on > your client machines? This way your central computer can call registered > methods (or remote objects in case of Pyro) on the client and execute > code there (that reports all sorts of stuff you want to know). Or have > each client call into a central server, where it reports that stuff > itself. Many ways to skin a cat. > > Regards, > Irmen de Jong I'm thinking maybe the client service will have a small number of generic features, such as reading WMI and SNMP values. That way the server still dictates the work to be done (i.e. XMLRPC returns which WMI/SNMP values to query), and the client remains relatively focused and straightforward. -- http://mail.python.org/mailman/listinfo/python-list
Writing code to be optimizable
Sometimes I want to prototype a program in Python, with the idea of optimizing it later by rewriting parts of it in C or Cython. But I usually find that in order to rewrite the slow parts, I end up writing those parts very much like C or C++ anyway, and I end up wondering what is the point of using Python in such a project. I liked the idea of Cython, mainly the idea of being able to write in pure Python, then create a file that modifies the pure Python file (with type declarations and such), but I ran into the same problems. In order to be able to modify the code, I can't make a lot of use of the really helpful things in Python like dicts and such. I have to dumb down Python to where I'm basically writing C code in Python, so again I ask myself what is the point? Is it reasonable to prototype an application in Python that will require performance? Are there any recommendations on how to write code in such a way that it can later be optimized or replaced with a module written in C or Cython? Or any good examples of this being done that I could learn from? -- http://mail.python.org/mailman/listinfo/python-list
Install Python on Windows without Start Menu icons?
Is it possible to automate the Python installation on Windows using the MSI file so it does not add a Start Menu folder? I would like to push out Python to all of my office workstations, but I'd like for it to be relatively silent from the user's point of view. -- http://mail.python.org/mailman/listinfo/python-list
Re: Install Python on Windows without Start Menu icons?
On Dec 5, 2:01 am, Wolfgang Strobl wrote: > "Pedro Henrique G. Souto" : > > >On 02/12/2011 16:34, snorble wrote: > >> Is it possible to automate the Python installation on Windows using > >> the MSI file so it does not add a Start Menu folder? I would like to > >> push out Python to all of my office workstations, but I'd like for it > >> to be relatively silent from the user's point of view. > > >If you just want to run python scripts in those machines (not developing > >in it), you can use something like py2exe [http://www.py2exe.org/]. > > That doesn't answer the question. > > Snorble might use "ORCA", a MSI editor from Microsoft. > > http://forums.frontmotion.com/viewtopic.php?f=10&t=837 > > discusses a similar question for Firefox. > > I haven't tried it myself, but would give it a try. > > -- > Thank you for observing all safety precautions Thank you! I got it working using Orca. Initially I had removed all of the rows from the Shortcut table and saved the .msi file, but the resulting .msi file was only about 600 KB (the original .msi file is about 15 MB). I had to create a .mst transform file, and that allows Python to install without any Start Menu entries. For reference, here's what I did. I opened the python-2.7.2.msi file in Orca, then click the Transform menu, then New Transform. Then go to the Shortcut table and highlight all of the entries and press the Delete key, and acknowledge that it will delete all of the rows. Then click the Transform menu and click Generate Transform and save it (python-2.7.2-no-icons.mst in my case). Once you have the .mst file, you can install it from the command line: msiexec /i python-2.7.2.msi TRANSFORMS=python-2.7.2-no-icons.mst Or to silently install: msiexec /qn /i python-2.7.2.msi TRANSFORMS=python-2.7.2-no-icons.mst -- http://mail.python.org/mailman/listinfo/python-list
Python Pop Quiz
1. Do you like Python? 2. Do you think Python is good? 3. Do you think Python is real good? 4. What is your favorite version of Python? 5. Because of Python, do you think it will be easier to take over the world? If so, when? If not, when? 7. How many Z80 assembly language programmers does it take to equal one Python guru? Essay: "C++ is better than C", agree or disagree? (four word maximum) Bonus: A rabbi walks into a bar while nursing a baby goat. He is closely followed by a priest, and a Perl hacker. Explain. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to do this in python with regular expressions
On May 25, 6:51 am, Jia Lu <[EMAIL PROTECTED]> wrote: > Hi all > > I'm trying to parsing html with re module. > > html = """ > > > > DATA1DATA2DATA3 HT>DATA4 > > > DATA5DATA6DATA7DATA8 > > > """ > > I want to get DATA1-8 from that string.(DATA maybe not english words.) > Can anyone tell me how to do it with regular expression in python? > > Thank you very much. # example1.py # This example will print out more than what's in the HTML table. It would also print # out text between tags, and so on. import HTMLParser class DataParser(HTMLParser.HTMLParser): def handle_data (self, data): data = data.strip() if data: print data html = ''' DATA1DATA2DATA3DATA4 DATA5DATA6DATA7DATA8 ''' parser = DataParser() parser.feed(html) parser.close() example1.py output: $ python example1.py DATA1 DATA2 DATA3 DATA4 DATA5 DATA6 DATA7 DATA8 # example2.py # This example uses the re module to pull out only the table portions of HTML. This # should only print out data between tags. Notice that there is some # data between the tags that is not present in the output. import HTMLParser import re class DataParser(HTMLParser.HTMLParser): def handle_data (self, data): data = data.strip() if data: print data html = ''' body data 1 table 1 data 1 table 1 data 2 table 2 data 1 table 2 data 2 body data 2 ''' tables_list = re.findall('.*?', html, re.DOTALL | re.IGNORECASE) tables_html = str.join(' ', tables_list) parser = DataParser() parser.feed(tables_html) parser.close() example2.py output: $ python example2.py table 1 data 1 table 1 data 2 table 2 data 1 table 2 data 2 # example3.py # This example does basically the same thing as example2.py, but it uses HTMLParser # to keep track of whether the data is between tags. import HTMLParser class DataParser(HTMLParser.HTMLParser): def __init__ (self): HTMLParser.HTMLParser.__init__(self) self.table_count = 0 def handle_starttag (self, tag, attrs): if tag == 'table': self.table_count += 1 def handle_endtag (self, tag): if tag == 'table': self.table_count -= 1 def handle_data (self, data): data = data.strip() if data and self.table_count > 0: print data html = ''' body data 1 table 1 data 1 table 1 data 2 table 2 data 1 table 2 data 2 body data 2 ''' parser = DataParser() parser.feed(html) parser.close() example3.py output: $ python example3.py table 1 data 1 table 1 data 2 table 2 data 1 table 2 data 2 -- http://mail.python.org/mailman/listinfo/python-list
Inheriting from int or long
I started creating a simple "bits" class, intended to act like a array of bits. This was my initial idea, basically just overriding the string representation to display the bitmask (so far): class bits(long): def __str__ (self): s = '' if self == 0L: s += '-' else: x = self while x >= 1: if x & 1L: s = '#' + s else: s = '-' + s x >>= 1 return s My thought was this will act like a Long, and so should act like an array of bits with arbitrary precision, supporting the standard bitwise operations, along with others I may add. >>> import bits >>> b = bits.bits(32) >>> b 32L >>> print b #- >>> b = bits.bits(35) >>> print b #---## >>> b = bits.bits(36) >>> print b #--#-- >>> b <<= 1 >>> print b 72 So obviously when I attempt a bitwise operation (ex. b <<= 1), b is being assigned the result of b << 1, which is a Long. >>> b = bits.bits(36) >>> type(b) >>> type (b << 1) Is there any way around this without reimplementing all of the bitwise operators? It's not the biggest deal to reimplement the operators, but it kind of defeats the benefit of inheriting from an integer type. If there isn't a way around this, then I am curious in what situations it would be beneficial to inherit from an int or long. This issue seems more related to numeric types, since they are so centered around operations that involve assignment, as opposed to, say, a List, which has some operators (ex. +=), but does not depend on them (ex. use append() instead). -- http://mail.python.org/mailman/listinfo/python-list
How to use Python well?
I use Python a lot, but not well. I usually start by writing a small script, no classes or modules. Then I add more content to the loops, and repeat. It's a bit of a trial and error learning phase, making sure I'm using the third party modules correctly, and so on. I end up with a working script, but by the end it looks messy, unorganized, and feels hacked together. I feel like in order to reuse it or expand it in the future, I need to take what I learned and rewrite it from scratch. If I peeked over a Python expert's shoulder while they developed something new, how would their habits differ? Do they start with classes from the start? I guess I'm looking for something similar to "Large Scale C++ Software Design" for Python. Or even just a walkthrough of someone competent writing something from scratch. I'm not necessarily looking for a finished product that is well written. I'm more interested in, "I have an idea for a script/program, and here is how I get from point A to point B." Or maybe I'm looking for is best practices for how to organize the structure of a Python program. I love Python and I just want to be able to use it well. -- http://mail.python.org/mailman/listinfo/python-list
Packaging question
My question is, why do the modules bar and foo show up in mypack's dir()? I intend for Foo (the class foo.Foo) and Bar (the class bar.Bar) to be there, but was not sure about the modules foo and bar. My big picture intention is to create smaller modules, but more of them (like I am used to doing with C++), and then use a package to organize the namespace so I'm not typing out excessively long names and making the code less readable. Is that a reasonable approach to developing Python programs? $ ls mypack/*.py bar.py foo.py __init__.py $ cat mypack/__init__.py from foo import Foo from bar import Bar $ python Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import mypack >>> dir(mypack) ['Bar', 'Foo', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'bar', 'foo'] >>> -- http://mail.python.org/mailman/listinfo/python-list