Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset spyder and restart from within running application #2423

Merged
merged 25 commits into from
Jul 17, 2015
Merged

Reset spyder and restart from within running application #2423

merged 25 commits into from
Jul 17, 2015

Conversation

goanpeca
Copy link
Member

@goanpeca goanpeca commented May 7, 2015

Fixes #2401


Description

Adds a new entry on the tools menu for reseting spyder from within the application

image

Or as an option in preferences... decision pending
image
After clicking a message box will ask to confirm, probably the message can be more explanatory so the user knows what he\she is about to do.

image

Todo

  • Agree on location of option
  • Agree on text of the new option

@Nodd
Copy link
Contributor

Nodd commented May 7, 2015

I would put it in the general tab in the preferences window.

@goanpeca
Copy link
Member Author

goanpeca commented May 7, 2015

That feels weird, cause the preferences tab defines behaviors not actions.

This is an action, and it would be nice if it has a straightforward place for it.

@Nodd
Copy link
Contributor

Nodd commented May 7, 2015

Yeah, but it is an action applied to the behaviors !
It could be added as another pushbutton along with Apply, OK and Cancel.

@goanpeca
Copy link
Member Author

goanpeca commented May 7, 2015

In that case I prefer adding the extra button.


Opinions @spyder-ide/core-developers?

@goanpeca
Copy link
Member Author

@blink1073, @SylvainCorlay, @ccordoba12 any comments on this one?

@blink1073
Copy link
Contributor

I like it as part of the Tools menu, as it is a global action.

@goanpeca
Copy link
Member Author

goanpeca commented Jun 5, 2015

@SylvainCorlay? @ccordoba12 comments?

@Nodd
Copy link
Contributor

Nodd commented Jun 5, 2015

I really think that resetting the preferences should be done from the preference window. That's the same reason why resetting shortcuts is done from the shortcuts tab.

@goanpeca
Copy link
Member Author

goanpeca commented Jun 5, 2015

I understand my dear, that is why I said, if it was going to be there, then it should be a button next to apply, ok, cancel, etc....

But I would like to hear from @SylvainCorlay and @ccordoba12

@goanpeca
Copy link
Member Author

goanpeca commented Jun 5, 2015

@Nodd there might be a reason to keep the restart option outside. Sometimes if there is an error or conflict the preferences dialog might not open, in which case restarting and reseting could not be done from within the gui.

@Nodd
Copy link
Contributor

Nodd commented Jun 5, 2015

#2412 should lower the probability of this happening. Also it's still possible to use the commandline switch or remove the directory by hand (of course it's less user-friendly).

@goanpeca
Copy link
Member Author

Ok @spyder-ide/core-developers this is the other option for the button.

This is a very small PR I would like to get off my back so please take a look at:

  • Location. Tools menu or Preferences dialog?, or both.
    • image
    • image
  • Text of message
  • Any comments on code?

Cheers

@@ -943,4 +950,4 @@ def apply_settings(self, options):
if self.main.historylog is not None:
self.main.historylog.apply_plugin_settings(['color_scheme_name'])
if self.main.inspector is not None:
self.main.inspector.apply_plugin_settings(['color_scheme_name'])
self.main.inspector.apply_plugin_settings(['color_scheme_name'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a newline here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@goanpeca
Copy link
Member Author

@Nodd Fixed

pid_reset = p.pid
except Exception as error:
print(command)
print(error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the traceback module would be nicer here, since it prints the full traceback as if the Exception wasn't catched. You can use traceback.print_exc() with no arguments, it prints the right thing at the right place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I will do :)

@goanpeca
Copy link
Member Author

@Nodd so you suggest something regarding the "infinite" loop?... or should we just let it roll and see how it works?

@@ -713,6 +713,9 @@ def create_edit_action(text, tr_text, icon):
module_completion.reset(),
tip=_("Refresh list of module names "
"available in PYTHONPATH"))
reset_spyder_action = create_action(
self, _("Reset Spyder to factory defaults"),
triggered=lambda: self.reset_spyder())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid the lambda here I think, using self.reset_spyder directly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True!

@Nodd
Copy link
Contributor

Nodd commented Jun 11, 2015

I think the correct behaviour is to wait something like 30s, and if it's not finished, kill the process, stop the restart and display a QMessageBox with an error.
I'm afraid that if we let the infinite loop it'll bite us sometimes in the future for whatever reason...

except Exception as error:
print(command)
traceback.print_exc()
time.sleep(15)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a problem here, the restart should be stopped instead of waiting 15s. This way the error will show up in the internal console.
Actually that means that you don't need to use traceback.print_exc(), just reraise the exception!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I get you... by internal console you mean? at this point we already left the initial spyder instance and we are inside the restart script. I will add an extra flag so that the restart stops and a QMessageBox displays something.

@goanpeca
Copy link
Member Author

Ok @Nodd I added a series of checks for better error handling which include a display of a message box in case errors occur, including close, reset and restart errors. Errors catched in the try,except part will also display the actual error. Errors based on too long running time will not display the error, but a friendly message....

while True:
max_counter = 1500 # Max loops to perform before aborting
counter = 0
while counter < max_counter: # This is equivalent to ~ 5 minute (1500*0.2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A for loop maybe ? ;)

# Before launching a new Spyder instance we need to make sure that the
# previous one has closed. We wait for a fixed and "reasonable" amount of
# time and check, otherwise an error is launched
wait_time = 60*5 if IS_WINDOWS else 60*3 # Seconds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we discussed this with @blink1073 and @SylvainCorlay and all of us agree that these waiting times are way too big. We think nobody is going to wait 3 min, much less 5 min, for Spyder to start :-)

So our proposal for this is: 30 sec for Linux/Mac (perhaps even 20), and 75 sec (90 tops) for Windows.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok Done...

30 and 90

@goanpeca
Copy link
Member Author

Any my mental health @ccordoba12 ?

@goanpeca
Copy link
Member Author

Anything holding this @ccordoba12?

RESTART_ERROR: _("Spyder restart error")}

if error:
e = error.__repr__()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

@ccordoba12
Copy link
Member

I think waiting 60 secs for --reset to work is too much because that would be added to the restart time, right?

Also, I'd like to discuss how the logic for reset + restart works. So restart_app calls spyder --reset first and then it closes the app, or is the other way around?

@goanpeca
Copy link
Member Author

Ok. When you restart first we wait for spyder to close. If that happenned before the max wait time then we launch the reset process, if that went fine and took less than the stated time then the new spyder instance is launched.

@ccordoba12
Copy link
Member

So this means a user could have to wait up to (30 or 90) + 60 secs for a reset (plus the time it take for a new instance to appear).

Can we reduce the time to reset to 20 secs or so? It usually doesn't take that long ;-)

@goanpeca
Copy link
Member Author

Yes, you are correct.

Sure, 20 secs is fine (I guess... we will know otherwise!)

@goanpeca
Copy link
Member Author

Anything besides that ?

@goanpeca
Copy link
Member Author

Anything else @ccordoba12 ?

@ccordoba12
Copy link
Member

Ok, merging this with @goanpeca (in person) for his own mental health :-P

ccordoba12 added a commit that referenced this pull request Jul 17, 2015
Reset spyder and restart from within running application
@ccordoba12 ccordoba12 merged commit c759852 into spyder-ide:master Jul 17, 2015
@blink1073
Copy link
Contributor

woot!

@goanpeca goanpeca deleted the reset branch August 3, 2015 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to reset settings from the Main Window
5 participants