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

pyFDA doesn't shut down properly #8

Closed
chipmuenk opened this issue Sep 9, 2015 · 14 comments
Closed

pyFDA doesn't shut down properly #8

chipmuenk opened this issue Sep 9, 2015 · 14 comments
Labels
Milestone

Comments

@chipmuenk
Copy link
Owner

When closing the application by closing the window or by clicking the "Quit" button, the python kernel crashes (Windows 7, 64 bit). I don't know whether the same happens under other OS's.

@chipmuenk chipmuenk added the bug label Sep 9, 2015
@chipmuenk chipmuenk added this to the 0.1 milestone Sep 9, 2015
@cfelton
Copy link
Collaborator

cfelton commented Sep 10, 2015

Similar behavior on OS X and Linux Ubuntu. The python interrupter doesn't crash instantly after a close, it takes awhile (20 seconds). Segmentation fault on Linux and Unexpected failure on OS X.

@chipmuenk
Copy link
Owner Author

Under Windows it only takes one or two seconds instead of 20 seconds, but there is a delay. The problem could be due to the hierarchy of widgets:

A simple widget like

%run -m pyfda.input_widgets.input_freq_specs

can be terminated without problem.

A more complex widget like

%run -m pyfda.input_widgets.input_specs

sometimes can be terminated by closing the window (but sometimes the kernel dies), using the "Quit" button never works.

On the other hand, the even more complex widget input_tab_widgets can be closed without problems (so far). Strange.

@chipmuenk
Copy link
Owner Author

ahh, that was a bit hasty:

%run -m pyfda.input_widgets.input_tab_widgets

and terminate it using the "Quit" button lets the kernel die as well when attempting to rerun the above line.

@chipmuenk
Copy link
Owner Author

Problem could be in the _delEntry method of input_freq_specs.py (and other modules).

@chipmuenk
Copy link
Owner Author

I had hoped the issue might be related to infinite signal-slot loops - but after cleaning up the signal-slot mess the issue still exists.

Strange:
python -m pyfda.plot_widgets.plot_tab_widgets runs and quits without problem
python -m pyfda.input_widgets.input_filter runs and quits without problem
(same for all other non-hierarchical subwidgets)
python -m pyfda.input_widgets.input_specs runs but crashes when trying to quit it

Ideas, anyone?

@vuki
Copy link

vuki commented Mar 7, 2016

I googled for this issue. It seems to be a general problem with the way PyQt is written. You're not doing anything wrong, it's just that the order of calling the destructors is undefined.

It seems that the only workaround is sip.setdestroyonexit(False). I tried this in your code and it works.

See here for info:

http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html#object-destruction-on-exit

http://stackoverflow.com/questions/24522327/consequences-of-avoiding-pyqt-program-crash-on-exit-by-using-sip-setdestroyonexi

@chipmuenk
Copy link
Owner Author

That's a good point, I've read about the sip module and sip.setdestroyonexit() a few times as well during the last week, but I had and have done some really nasty things in the software like deleting widgets that don't exist any longer, creating instances without relationship to the main window and so on. As a consequence, some other bugs (issue #6 and #7) disappeared with PR #23 as well.

So I guess I'll use sip.setdestroyonexit() as an intermediate fix but try to clean up the plotting routines inheritance mess anyway.

@chipmuenk
Copy link
Owner Author

@vuki: Could you tell me at which level you set sip.setdestroyonexit(False) ? I tried it in main() and in the constructor of the pyfdax class, but it had no effect.

@vuki
Copy link

vuki commented Mar 8, 2016

Works for me. File pyfdax.py, top of the file:

from sip import setdestroyonexit

Then:

if __name__ == '__main__':
    setdestroyonexit(False)
    main()

Any place before calling app_exec_() should work. I use python 3.5 if that matters.

BTW, when i press Quit button in the left pane, it does not ask me for confirmation.

@chipmuenk
Copy link
Owner Author

Confirmed and fixed, unfortunately it only works for Python 3.x.
Under Python 2.x the problem can be reduced to adding plot_tab_widgets with just one (any) plot_widget. When no plot widget is instantiated, the plot_tab_widgets are blank (naturally) but the application shuts down cleanly.

@chipmuenk
Copy link
Owner Author

chipmuenk commented May 2, 2016

After fiddling around with the dynamic creation and deletion of subwidgets, this seems to be one of the problems: Adding in input_filter.py

337: fb.fil_inst.destruct_UI() # disconnect signals from dyn. widget

an attempt to disconnect signals before deleting corresponding subwidgets crashes the subwidget upon exit (started with python -m pyfda.input_widgets.input_filter

@chipmuenk
Copy link
Owner Author

chipmuenk commented Sep 9, 2016

It seems, the problem can be boiled down to Qt objects without parents, creating havoc when the app is closed. Currently, the app can be started and closed without problems when no plot widget is instantiated.

The following parts of the app are / have been especially suspect:

  • Dynamic creation and deletion of the amplitude, weight and frequency spec fields depending on the filter type -> now subwidgets are created as needed, superfluous ones are hidden instead of deleted
  • Instantiation of all filter widgets at startup to build the filter tree. This instantiated filter widgets at the same time, leaving them dangling in the air. -> Construction of filter widgets is now outside the init method
  • Dynamic creation and destruction of filter widgets: Now, the top level widget is referenced and deleted in a proper fashion, signals are connected and disconnected
  • The handling of the common plot_utilities and the Matplotlib menu bar in the plot routines is very fishy -> major rework needed ...

@chipmuenk
Copy link
Owner Author

Fixed in v0.1rc1! Unexpectedly, the last root cause was a double instantiation of a QSpacerItem under the same name "spacer" ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants