MCPcopy Create free account
hub / github.com/ActiveState/code / start

Method start

recipes/Python/577524_Python_Sessions/recipe-577524.py:105–131  ·  view source on GitHub ↗

Start the session

(self)

Source from the content-addressed store, hash-verified

103 return (S_ID, self.__sid)
104
105 def start(self):
106 """Start the session"""
107 if self.started:
108 return True # session cannot be started more than once per script
109
110 self._flock = FileLock(self.path)
111 self._flock.acquire()
112
113 # load the session if it exists
114 if os.path.exists(self.path):
115 with open(self.path, "rb") as f:
116 self.data = dict(load(f))
117 self.data["__date_loaded__"] = TODAY
118
119 else: # create a session
120 with open(self.path, "wb") as f:
121 self.data = {"__date_loaded__":TODAY}
122
123 # the session is officially started!
124 self.started = True
125
126 # store the sid in the cookie
127 self.cookie[S_ID] = self.__sid
128 self.cookie[S_ID]["expires"] = str(self.expires)
129 self.cookie[S_ID]["version"] = "1"
130
131 return True
132
133 def commit(self):
134 """Commit the changes to the session"""

Callers 1

startFunction · 0.95

Calls 7

strFunction · 0.85
FileLockClass · 0.70
openFunction · 0.50
dictFunction · 0.50
loadFunction · 0.50
acquireMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected