Never mind.  I hadn't realized that updates and inserts from a
background process needs an explicit db.commit().   Seems to be
working correctly now by just blindly calling db.commit() after the
insert returns.


On Jul 24, 1:02 pm, Michael Ellis <[email protected]> wrote:
> I'm running a background process started with web2py -S as described
> in the web2py book.   The background process receives data from an
> external process and inserts it into a table in the sqlite3 db.  This
> appears to be succeeding but when I try to access the table from the
> admin page using a normal instance of web2py,  the inserted records
> are not in the table.
>
> Here's the function that's being called in the background process:
>
> def v2_data_insert(timestamp, sensorid,
>                    ch1=None, ch2=None, ch3=None, ch4=None, ch5=None,
> ch6=None,
>                    flowrate=None, flowtemp=None, erate=None,
>                    chargev=None, battv=None, sensorv=None):
>
>     print "Entering v2_data_insert"
>     before = db(db.t_v2_data.id > 0).count()
>     db.t_v2_data[0] = dict(f_timestamp_datetime = timestamp,
>                            f_sensor_reference = sensorid,
>                            f_ch1_value_double = ch1,
>                            f_ch2_value_double = ch2,
>                            f_ch3_value_double = ch3,
>                            f_ch4_value_double = ch4,
>                            f_ch5_value_double = ch5,
>                            f_ch6_value_double = ch6,
>                            f_flow_rate_double = flowrate,
>                            f_flow_temp_double = flowtemp,
>                            f_energy_rate_double = erate,
>                            f_battery_charger_double = chargev,
>                            f_battery_volts_double = battv,
>                            f_sensor_volts_double = sensorv)
>
>     after = db(db.t_v2_data.id > 0).count()
>     print "before: %d, after: %d" % (before, after)
>     print "Leaving v2_data_insert"
>
> At each insert, I see the printouts in the terminal window and the
> after count is always one greater than the before count, e.g.
>
> Entering v2_data_insert
> before: 6611, after: 6612
> Leaving v2_data_insert
>
> Entering v2_data_insert
> before: 6612, after: 6613
> Leaving v2_data_insert
>
> and so on,  but the new records aren't visible in the other web2py
> process from the admin page -- even if I stop the process and restart
> it.
>
> Just to be clear, the background process is started from within the
> web2py directory with
>
> python2.7 web2py.py -S sunrex -N -M -R /Users/mellis/
> fls_data_handler.py
>
> and the normal instance is started with
>
> python2.7 web2py.py -a password
>
> This has got to be something stupid I'm doing but I'm stumped at the
> moment!
>
> Thanks,
> Mike

Reply via email to