GTG

Merge lp:~huxuan/gtg/bug-907676 into lp:~gtg/gtg/old-trunk

Proposed by Xuan (Sean) Hu
Status: Rejected
Rejected by: Izidor Matušov
Proposed branch: lp:~huxuan/gtg/bug-907676
Merge into: lp:~gtg/gtg/old-trunk
Diff against target: 97 lines (+30/-7)
2 files modified
GTG/backends/backend_localfile.py (+28/-7)
GTG/tests/test_backends.py (+2/-0)
To merge this branch: bzr merge lp:~huxuan/gtg/bug-907676
Reviewer Review Type Date Requested Status
Izidor Matušov Disapprove
Xuan (Sean) Hu (community) Needs Resubmitting
Review via email: mp+103529@code.launchpad.net

Description of the change

It's a trial to solve bug #907676.
Welcome to any suggestions or criticism.
Feel free to comment your opinion down

To post a comment you must log in.
lp:~huxuan/gtg/bug-907676 updated
1177. By Xuan (Sean) Hu

backend_localfile.py

1) remove test code. (forgive silly me)

1178. By Xuan (Sean) Hu

backend_localfile.py

1) a little code revise to be more pylint.
Though there exist more.

Revision history for this message
Izidor Matušov (izidor) wrote :

Your solution looks good and should work in the most of the situation. You might not get right this kind of situation:
" You get many requests in 20 seconds. You filter them because it is in burst. But then you have no save requests for long time like 30 minutes. Afterwards GTG crashes or user turn off the computer without closing GTG - the changes in the first 20 seconds are lost. "

Do you see that usecase? I propose to solve this bug by creating a timer which save XML and then timer is deleted. If the timer exists, save action is thrown away (it is already going to be saved). You might need to add locks to prevent modification of XML while saving XML.

review: Needs Fixing (code)
Revision history for this message
Bertrand Rousseau (bertrand-rousseau) wrote :

I don't think we'd like to keep that particular line ;-)

+ print 'fuck'

2012/4/26 Izidor Matušov <email address hidden>:
> Review: Needs Fixing code
>
> Your solution looks good and should work in the most of the situation. You might not get right this kind of situation:
> " You get many requests in 20 seconds. You filter them because it is in burst. But then you have no save requests for long time like 30 minutes. Afterwards GTG crashes or user turn off the computer without closing GTG - the changes in the first 20 seconds are lost. "
>
> Do you see that usecase? I propose to solve this bug by creating a timer which save XML and then timer is deleted. If the timer exists, save action is thrown away (it is already going to be saved). You might need to add locks to prevent modification of XML while saving XML.
> --
> https://code.launchpad.net/~huxuan/gtg/bug-907676/+merge/103529
> You are subscribed to branch lp:gtg.

--
Bertrand Rousseau

Revision history for this message
Xuan (Sean) Hu (huxuan) wrote :

izidor:
Got that, I will try to implement it.

Bertrand Rousseau:
Really sorry for the testing code. I did have delete it.

lp:~huxuan/gtg/bug-907676 updated
1179. By Xuan (Sean) Hu

backend_localfile.py

1) Make timer for saving

Revision history for this message
Xuan (Sean) Hu (huxuan) wrote :

hi, I have resubmit and wish your more suggestion.

Revision history for this message
Xuan (Sean) Hu (huxuan) :
review: Needs Resubmitting
lp:~huxuan/gtg/bug-907676 updated
1180. By Xuan (Sean) Hu

backend_localfile.py

1) revised for silly logical error

1181. By Xuan (Sean) Hu

backend_localfile.py

1) silly repo error (thanks to pylint)
2) docstring revise

1182. By Xuan (Sean) Hu

backend_localfile.py

1) silly logical error.

1183. By Xuan (Sean) Hu

backend_localfile.py

1) bug fix for error indent

1184. By Xuan (Sean) Hu

backend_localfile.py

1) remove self.timer_exist for simplier code

1185. By Xuan (Sean) Hu

Merge from lp:gtg

Revision history for this message
Izidor Matušov (izidor) wrote :

Could you explain me why do you need self.timer_backup?

The only way how to call savexml from set_task & remove_task should be through a timer. In other words, there can't savexml in set_task & remove_task methods.

Please, decrease Timer time to shorter interval like 1 or 2 seconds. (This should prevent bursts of savexml calls but still saving enough and not lose data)

If something is not clear, feel free to contact me directly :)

review: Needs Fixing (code)
lp:~huxuan/gtg/bug-907676 updated
1186. By Xuan (Sean) Hu

merge from lp:gtg

1187. By Xuan (Sean) Hu

revise according to izidor's comment:

1) backend_localfile.py: remove redundant savexml, reduce timer interval
2) test_backends.py: add time.sleep to wait timer so as to pass the test

1188. By Xuan (Sean) Hu

merge from lp:gtg

Revision history for this message
Xuan (Sean) Hu (huxuan) wrote :

izidor, hi

Sorry for reply so late. I'm just back from thesis season with everything almost done.

I just use self.time_backup as a sign of whether to create backup localfile. If remove that then how should we judge whether savexml should just save with rewrite or as a backup?
I have remove the redundant savexml in set_task and remove_task, but find if fail in the test caused by the timer. I add a time.sleep so as to make it pass. just note it here for attention.
The code still need some test and revise. I will try to get you in the irc channel.

lp:~huxuan/gtg/bug-907676 updated
1189. By Xuan (Sean) Hu

make sleep with 2 sec to avoid potential make check error

Revision history for this message
Izidor Matušov (izidor) wrote :

As I described in the bug and on IRC, the bug should be solved by changing internal interface. Closing as "rejected". Nothing personal :)

review: Disapprove

Unmerged revisions

1189. By Xuan (Sean) Hu

make sleep with 2 sec to avoid potential make check error

1188. By Xuan (Sean) Hu

merge from lp:gtg

1187. By Xuan (Sean) Hu

revise according to izidor's comment:

1) backend_localfile.py: remove redundant savexml, reduce timer interval
2) test_backends.py: add time.sleep to wait timer so as to pass the test

1186. By Xuan (Sean) Hu

merge from lp:gtg

1185. By Xuan (Sean) Hu

Merge from lp:gtg

1184. By Xuan (Sean) Hu

backend_localfile.py

1) remove self.timer_exist for simplier code

1183. By Xuan (Sean) Hu

backend_localfile.py

1) bug fix for error indent

1182. By Xuan (Sean) Hu

backend_localfile.py

1) silly logical error.

1181. By Xuan (Sean) Hu

backend_localfile.py

1) silly repo error (thanks to pylint)
2) docstring revise

1180. By Xuan (Sean) Hu

backend_localfile.py

1) revised for silly logical error

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'GTG/backends/backend_localfile.py'
--- GTG/backends/backend_localfile.py 2012-03-05 15:23:05 +0000
+++ GTG/backends/backend_localfile.py 2012-05-30 08:35:23 +0000
@@ -27,6 +27,7 @@
2727
28import os28import os
29import uuid29import uuid
30import threading
3031
31from GTG import _32from GTG import _
32from GTG.backends.genericbackend import GenericBackend33from GTG.backends.genericbackend import GenericBackend
@@ -50,8 +51,8 @@
50 # default path for filenames51 # default path for filenames
51 DEFAULT_PATH = CoreConfig().get_data_dir() 52 DEFAULT_PATH = CoreConfig().get_data_dir()
5253
53 # General description of the backend: these are used to show a description of54 # General description of the backend: these are used to show a description
54 # the backend to the user when s/he is considering adding it.55 # of the backend to the user when s/he is considering adding it.
55 # BACKEND_NAME is the name of the backend used internally (it must be56 # BACKEND_NAME is the name of the backend used internally (it must be
56 # unique).57 # unique).
57 # Please note that BACKEND_NAME and BACKEND_ICON_NAME should *not* be58 # Please note that BACKEND_NAME and BACKEND_ICON_NAME should *not* be
@@ -111,6 +112,22 @@
111 # Make safety daily backup after loading112 # Make safety daily backup after loading
112 cleanxml.savexml(self._parameters["path"], self.doc, backup=True)113 cleanxml.savexml(self._parameters["path"], self.doc, backup=True)
113114
115 # Set timer as None and mark it not backup
116 self.timer = None
117 self.timer_backup = False
118
119 def timer_end(self):
120 """ Save and set timer as None and mark it not backup """
121 cleanxml.savexml(self._parameters["path"], self.doc, \
122 backup=self.timer_backup)
123 self.timer = None
124 self.timer_backup = False
125
126 def timer_start(self):
127 """ Start timer for saving """
128 self.timer = threading.Timer(1, self.timer_end)
129 self.timer.start()
130
114 def initialize(self):131 def initialize(self):
115 """ This is called when a backend is enabled """132 """ This is called when a backend is enabled """
116 super(Backend, self).initialize()133 super(Backend, self).initialize()
@@ -131,8 +148,8 @@
131 self._parameters["path"], "project")148 self._parameters["path"], "project")
132149
133 def start_get_tasks(self):150 def start_get_tasks(self):
134 """ This function starts submitting the tasks from the XML file into GTG core.151 """ This function starts submitting the tasks from the XML file into
135 It's run as a separate thread.152 GTG core. It's run as a separate thread.
136 153
137 @return: start_get_tasks() might not return or finish154 @return: start_get_tasks() might not return or finish
138 """155 """
@@ -178,8 +195,9 @@
178 modified = True195 modified = True
179196
180 #if the XML object has changed, we save it to file197 #if the XML object has changed, we save it to file
181 if modified and self._parameters["path"] and self.doc :198 if modified and self._parameters["path"] and self.doc \
182 cleanxml.savexml(self._parameters["path"], self.doc)199 and not self.timer:
200 self.timer_start()
183201
184 def remove_task(self, tid):202 def remove_task(self, tid):
185 """ This function is called from GTG core whenever a task must be203 """ This function is called from GTG core whenever a task must be
@@ -195,4 +213,7 @@
195213
196 #We save the XML file only if it's necessary214 #We save the XML file only if it's necessary
197 if modified:215 if modified:
198 cleanxml.savexml(self._parameters["path"], self.doc, backup=True)216 if self.timer:
217 self.timer_backup = True
218 else:
219 self.timer_start()
199220
=== modified file 'GTG/tests/test_backends.py'
--- GTG/tests/test_backends.py 2012-03-05 15:23:05 +0000
+++ GTG/tests/test_backends.py 2012-05-30 08:35:23 +0000
@@ -27,6 +27,7 @@
27import unittest27import unittest
28import os28import os
29import xdg29import xdg
30import time
3031
31# GTG imports32# GTG imports
32from GTG.backends import backend_localfile as localfile33from GTG.backends import backend_localfile as localfile
@@ -100,6 +101,7 @@
100 expectedres = True101 expectedres = True
101 beobj.remove_task("0@1")102 beobj.remove_task("0@1")
102 beobj.quit()103 beobj.quit()
104 time.sleep(2)
103 dataline = open(self.taskpath, 'r').read()105 dataline = open(self.taskpath, 'r').read()
104 if "0@1" in dataline:106 if "0@1" in dataline:
105 res = False107 res = False

Subscribers

People subscribed via source and target branches

to status/vote changes: