[Twisted-Python] Question about using the adbapi

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Mon May 9 07:03:12 EDT 2011


On 10:50 am, albert.brandl at weiermayer.com wrote:
>Hi!
>
>In the application I'm currently working on, we gather data from
>different sources and store them in a database, but only if the
>values have changed.
>
>One example is GPS information. We don't want to store hundreds of
>identical values that are sent by the receiver, so we have to compare 
>the
>last written row with the current latitude / longitude pair.
>
>I use a subclass of NMEARreceiver class to determine the current 
>latitude
>and longitude. Then I query the database using a ConnectionPool 
>instance
>to get the previous values for latitude and longitude. If the result
>differs from the current values, a new entry is stored, again using the
>ConnectionPool.
>
>The problem is: How do I "connect" the current latitude and longitude 
>to
>the database query? The query returns a Deferred object, but this 
>expects
>a callback with only one argument, the result of the query.

d.addCallback(f, x, y) will result in f(resultOfD, x, y)

Jean-Paul
>
>Storing them as instance variables of NMEAReceiver does not seem to be
>the right way, since I don't know how long it takes to query the 
>database
>- the relevant GPS information might be overwritten by a new NMEA
>telegram when the connection pool finally triggers the callback
>
>One workaround I've found is to add this information to the SQL query,
>but this seems quite weird to me (and doesn't work in the case that the
>query does not return a result).
>
>A different approach would be to implement a callback with three
>arguments (result, latitude and longitude), and wrap it in a lambda
>function that fills latitude and longitude with the current values.
>Would this would be a better way to handle this requirement?
>
>How would you implement this?
>
>Thanks & best regards,
>
>Albert
>--
>Albert Brandl
>Weiermayer Solutions GmbH      | Abteistraße 12, A-4813 Altmünster
>phone: +43 (0) 720 70 30 14    | fax: +43 (0) 7612 20 3 56
>web: http://www.weiermayer.com
>
>_______________________________________________
>Twisted-Python mailing list
>Twisted-Python at twistedmatrix.com
>http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python



More information about the Twisted-Python mailing list