Skip to content

Commit 78bc977

Browse files
committed
cisstInteractive: fixed pickle calls for Python 3
1 parent ea1380c commit 78bc977

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

cisstInteractive/code/ireTask.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Author(s): Peter Kazanzides
77
Created on: 2010-12-10
88
9-
(C) Copyright 2010 Johns Hopkins University (JHU), All Rights Reserved.
9+
(C) Copyright 2010-2025 Johns Hopkins University (JHU), All Rights Reserved.
1010
1111
--- begin cisst license - do not edit ---
1212
@@ -52,7 +52,7 @@ void ireTask::Initialize(void)
5252
required->AddEventHandlerWrite(&ireTask::Log, this,
5353
mtsManagerComponentBase::EventNames::PrintLog);
5454
}
55-
SetInitializationDelay(30.0); // Allow up to 30 seconds for it to start
55+
SetInitializationDelay(10.0); // Allow up to 10 seconds for it to start
5656
}
5757

5858
ireTask::~ireTask()

cisstInteractive/code/irepy/ireMain.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -599,17 +599,15 @@ def GetTypeString(self, obj):
599599
#-------------------------------------------------
600600

601601
def SaveHistoryToFile(self):
602-
# PK TODO: pickle not yet working in Python3
603-
if sys.version_info.major == 2:
604-
cmdlist = self.CommandHistoryListCtrl.GetAllItems()
605-
f = open(self.HISTORY_FILENAME, 'w')
606-
pickle.dump(cmdlist, f)
602+
cmdlist = self.CommandHistoryListCtrl.GetAllItems()
603+
f = open(self.HISTORY_FILENAME, 'wb')
604+
pickle.dump(cmdlist, f)
607605

608606
def LoadHistoryFromFile(self, fn=HISTORY_FILENAME):
609607
Data = []
610608
if os.path.isfile(fn):
611609
try:
612-
Data = pickle.load(open(fn))
610+
Data = pickle.load(open(fn, 'rb'))
613611
except Exception as error:
614612
msgdlg = wx.MessageDialog(self, str(error), "Load History", wx.OK | wx.ICON_ERROR)
615613
msgdlg.ShowModal()
@@ -693,13 +691,13 @@ def TruncateHistoryFile(self):
693691
# write the command file up to the selected line into the named file
694692
# fetch any existing list first and append to it
695693
try:
696-
archlist = pickle.load(open(fn))
694+
archlist = pickle.load(open(fn), 'rb')
697695
except IOError:
698696
archlist = []
699697
n=0
700698
for n in range(choice):
701699
archlist.append( cmdlist[n] )
702-
pickle.dump( archlist, open(fn, 'w'))
700+
pickle.dump( archlist, open(fn, 'wb'))
703701
text = "Your command history was archived to " + fn
704702
msgdlg = wx.MessageDialog(self, text, title, wx.OK | wx.ICON_INFORMATION)
705703
msgdlg.ShowModal()
@@ -836,7 +834,7 @@ def OnViewLogger(self, event):
836834
def OnLoadWorkspace(self, event):
837835
Filepath = py.editor.openSingle(directory='',wildcard='IRE Workspace (*.ws)|*.ws|All Files (*.*)|*.*').path
838836
if Filepath:
839-
File = open(Filepath)
837+
File = open(Filepath, 'rb')
840838
LoadWorkspaceFile(self.Shell.interp.locals, File)
841839
File.close()
842840
self.CheckScopeVariables()
@@ -848,7 +846,7 @@ def OnSaveWorkspace(self, event):
848846
(name, ext) = os.path.splitext(Filepath)
849847
if not ext:
850848
Filepath += '.ws'
851-
File = open(Filepath,'w')
849+
File = open(Filepath,'wb')
852850
SaveWorkspaceToFile(self.Shell.interp.locals, File)
853851
File.close()
854852

cisstInteractive/code/irepy/ireWorkspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def main():
7676
v1 = v2 = None
7777
print('v1 = ', v1, '\nv2 = ', v2)
7878
LoadFile(open('workspace'))
79-
Workspace = pickle.load(open('workspace'))
79+
Workspace = pickle.load(open('workspace', 'rb'))
8080
for Variable in Workspace:
8181
exec(Variable + " = Workspace['" + Variable + "']")
8282
print('v1 = ', v1, '\nv2 = ', v2)

0 commit comments

Comments
 (0)