I am sure there is a better way but this should do it:
from gluon import portalocker
def system_state():
import shelve
overall_state = "good"
lock_file=open('/dev/shm/from_machine_server.status.lock','r') ###
portalocker.lock(lock_file,portalocker.LOCK_EX) ###
write_file = shelve.open('/dev/shm/from_machine_server.status')
#Get all the data into the session first.
session.devices = write_file['devices']
session.sensors = write_file['sensors']
session.at_door = write_file['at_door']
print sorted(session.keys())
print "auth :", session.auth
import time
print time.time()
if write_file['debug']:
session.last_response = write_file['debug']
#This is to get the overall state of the machine...
if session.machine_ticker == write_file["ticker"]:
overall_state = 'bad'
print "no new ticker found...", session.machine_ticker,
write_file["ticker"]
return dict(overall_state = overall_state)
else:
print "new ticker found...", session.machine_ticker,
write_file["ticker"]
session.machine_ticker = write_file["ticker"]
write_file.close()
portalocker.unlock(lock_file) ###
lock_file.close() ###
return dict(overall_state = overall_state)
On Sep 22, 9:53 am, "Jason (spot) Brower" <[email protected]> wrote:
> Awww shoot. How do I do that? I found this... but it says that it
> doesn't work for windows.
> I need Linux and windows support. (Mac could be an
> option.)http://code.activestate.com/recipes/576591-simple-shelve-with-linux-f...
> BR,
> Jason Brower
>
> On Wed, Sep 22, 2010 at 4:47 PM, mdipierro <[email protected]> wrote:
> > I think your peoblem is that you are not locking the shelve file you
> > create. If you do not lock it it may get corrupted.
>
> > On Sep 22, 6:19 am, "Jason (spot) Brower" <[email protected]> wrote:
> >> I have some code and information about the sessions being lost...
> >> This method is called every two seconds.
> >> The printout is what I get. Notice... ON then OFF and repeated.
> >> I am the only user on the system, I have only one browser tab open,
> >> and I know that the file data it is pulling from is correct and
> >> accurate. You can see that with the ticker value. That is what it
> >> should be.
> >> Told you it was weird.
>
> >> controller.py
> >> 2KViewDownload
>
>