Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68563 > unrolled thread
| Started by | Peace <abhishek1899@gmail.com> |
|---|---|
| First post | 2014-03-19 15:05 -0700 |
| Last post | 2014-03-22 08:20 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
Problem with pickle and restarting a program Peace <abhishek1899@gmail.com> - 2014-03-19 15:05 -0700
Re: Problem with pickle and restarting a program dieter <dieter@handshake.de> - 2014-03-20 09:20 +0100
Re: Problem with pickle and restarting a program peace <abhishek1899@gmail.com> - 2014-03-20 11:28 -0700
Re: Problem with pickle and restarting a program dieter <dieter@handshake.de> - 2014-03-22 08:20 +0100
| From | Peace <abhishek1899@gmail.com> |
|---|---|
| Date | 2014-03-19 15:05 -0700 |
| Subject | Problem with pickle and restarting a program |
| Message-ID | <cc656034-01c4-430c-84f0-a181cef6560a@googlegroups.com> |
In my GUI, the user enters two values: cellNumber(Integer) and SerialNumber(String)
I have the following piece of code in my view/controller:
####################The following function is called after the user enters the cellnumber and serial number##############
def ListenForDetails(status):
cellNumber = status[0]
SerialNumber = status[1]
ModelInfo().CellList[cellNumber].receiveSerialNumber(SerialNumber)
------------------In my controller thread-----------------
class Controller(Thread):
def __init__(self):
Thread.__init__(self)
self.start()
def run(self):
global SynchronizationVariable
while SynchronizationVariable != 1:
time.sleep(0.01)
while 1:
StateChanged = False
for cells in ModelInfo().CellList:
rc = cells.PollCells()
if rc == 0:
StateChanged = True
if StateChanged:
ModelInfo().save()
time.sleep(1)
-------------------------------In my model.py script-------------------------------------
class CellInfo(): #This class encapsulates all the information present in a cell
def __init__(self,cellNo):
self.SerialNo = ""
self.cellNo = cellNo
def receiveSerialNumber(self, SerialNumber):
self.SerialNo = SerialNumber
def PollCells(self):
RC = self.StateMachine[self.CurrentState](self)
return RC
...all state machine functions here...
"""Model Info below"""
class ModelInfo(): #This class creates a list of cells.
def __init__(self):
print("Setting up a list of cells to iterate on")
self.CellList = [] #List of all the cell Objects
for index in xrange(0,24):
print(self.CellList)
self.CellList.append(CellInfo(index))
def save(self):
with open("RestoreInfo.p", "wb") as f:
pickle.dump(self,f)
Model = ModelInfo() #Constructs an empty model
"""IN MAIN (In the controller script)"""
if __name__ == '__main__':
if os.path.isfile( "RestoreInfo.p" ):
with open("RestoreInfo.p", "rb") as f:
model = pickle.load( f );
else:
model = model.ModelInfo();
The serial number field always remains empty even though I enter from the GUI and the receiveSerialNumber function is called and I explicitly initialize it to the variable in the model.
I'm trying to save the state of the program so that next time I open the application it resumes from where it left off. The problem is when I restart the application, the serial number is empty. What am I doing wrong here? Whenever I get a change in state (the RC value), I pickle and save to a file (restoreinfo.p). When I restart the application, the serial number is no longer there even though I enter it. Could you please let me know what is going wrong? Thank you.
[toc] | [next] | [standalone]
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2014-03-20 09:20 +0100 |
| Message-ID | <mailman.8292.1395303616.18130.python-list@python.org> |
| In reply to | #68563 |
Peace <abhishek1899@gmail.com> writes:
> ...
> The serial number field always remains empty even though I enter from the GUI and the receiveSerialNumber function is called and I explicitly initialize it to the variable in the model.
> I'm trying to save the state of the program so that next time I open the application it resumes from where it left off. The problem is when I restart the application, the serial number is empty. What am I doing wrong here? Whenever I get a change in state (the RC value), I pickle and save to a file (restoreinfo.p). When I restart the application, the serial number is no longer there even though I enter it. Could you please let me know what is going wrong? Thank you.
You may want to use debugging to determine what goes on in detail.
There are commercial debuggers with a graphical user interface
(maybe even free ones). Python comes with a simple command line
debugger ("pdb").
[toc] | [prev] | [next] | [standalone]
| From | peace <abhishek1899@gmail.com> |
|---|---|
| Date | 2014-03-20 11:28 -0700 |
| Message-ID | <11a691c7-2842-4d3a-b355-1e44652d7590@googlegroups.com> |
| In reply to | #68571 |
On Thursday, March 20, 2014 1:20:03 AM UTC-7, dieter wrote:
> Peace <> writes:
>
> > ...
>
> > The serial number field always remains empty even though I enter from the GUI and the receiveSerialNumber function is called and I explicitly initialize it to the variable in the model.
>
> > I'm trying to save the state of the program so that next time I open the application it resumes from where it left off. The problem is when I restart the application, the serial number is empty. What am I doing wrong here? Whenever I get a change in state (the RC value), I pickle and save to a file (restoreinfo.p). When I restart the application, the serial number is no longer there even though I enter it. Could you please let me know what is going wrong? Thank you.
>
>
>
> You may want to use debugging to determine what goes on in detail.
>
>
>
> There are commercial debuggers with a graphical user interface
>
> (maybe even free ones). Python comes with a simple command line
>
> debugger ("pdb").
I tried doing that. I still could not figure out what was wrong. Thank you.
[toc] | [prev] | [next] | [standalone]
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2014-03-22 08:20 +0100 |
| Message-ID | <mailman.8386.1395472819.18130.python-list@python.org> |
| In reply to | #68596 |
peace <abhishek1899@gmail.com> writes: > On Thursday, March 20, 2014 1:20:03 AM UTC-7, dieter wrote: > ... >> You may want to use debugging to determine what goes on in detail. > ... > I tried doing that. I still could not figure out what was wrong. Thank you. Debugging is often not easy. An essential strategy is "divide and conquer": i.e. you split the complete scenario into segments and analyse each segment to find out where the bad thing happens. Related to pickle, there is one point to lock at closely: where you "dump" the data. Verify, that you are dumping the correct (expected) data. If the data is not as you expect at that point, you must analyse the first part (from where the data was produced up to the dumping point); on the other hand, if the dumped data is correct, you would verify that "load" restores this same data (this will be very likely the case) and if it does why it became wrong afterward.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web