[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

20050623: python + LDM



Daryl,

I passed your message on to Steve Emmerson for consideration.
In my brief perusal, I see you have productDelimiter = '\003',
so I'm assuming you intend this only to be something for
the clear text products?

Steve Chiswell
Unidata User Support


>From: Daryl Herzmann <address@hidden>
>Organization: UCAR/Unidata
>Keywords: 200506231613.j5NGDeZu022545

>Hi Unidata,
>
>I mucked up a small peice of python code that bridges pqact and python via 
>Twisted Python.  Basically it allows for non-blocking processing of 
>products while the STDIN pipe remains open.  Currently, I am invoking 
>python for each product received, which is not good (Bad daryl!)
>
>I wanted to run this by you folks, before I sent a more polished version 
>to the ldm-users list.  Perhaps somebody else has already done this and I 
>suspect better!  Or there are some python hacks there that can comment on 
>this code...
>
>There are many reasons why this is interesting.  The main one being the 
>non-blocking nature and the ability for a long running python process that 
>is not reinvoked constantly....
>
>later,
>   daryl
>
>#=cut==== cat bridgefe.py =====
>
>#!/usr/bin/env python
>
>import ldmbridge
>from twisted.internet import reactor
>
>class myProductIngestor(ldmbridge.LDMProductReceiver):
>
>     # Here is where you would write your processing code!
>     def processData(self, data):
>         print "I would like to do something here"
>
>fact = ldmbridge.LDMProductFactory( myProductIngestor() )
>
>reactor.run()
>
>#=cut==== cat ldmbridge.py =====
>
>import sys, re
>
>from twisted.internet import stdio
>from twisted.protocols import basic
>from twisted.internet import reactor
>
>class LDMProductReceiver(basic.LineReceiver):
>     delimiter = '\n'
>     productDelimiter = '\003'
>
>     def __init__(self):
>         self.productBuffer = ""
>         self.setRawMode()
>
>     def rawDataReceived(self, data):
>         pos = data.find(self.productDelimiter)
>         if (pos == -1):
>             self.productBuffer += data
>         else:
>             self.productBuffer += data[:pos]
>             reactor.callLater(0, self.processData, self.productBuffer)
>             self.productBuffer = data[pos:]
>
>     def connectionLost(self, reason):
>         reactor.stop()
>
>     def processData(self, data):
>         raise NotImplementedError
>
>class LDMProductFactory( stdio.StandardIO ):
>
>     def __init__(self, protocol):
>         stdio.StandardIO.__init__(self, protocol)
>
>     def connectionLost(self, reason):
>         reactor.stop()
>
>
--
NOTE: All email exchanges with Unidata User Support are recorded in the
Unidata inquiry tracking system and then made publicly available
through the web.  If you do not want to have your interactions made
available in this way, you must let us know in each email you send to us.


NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.