adamerose / PandasGUI

A GUI for Pandas DataFrames
MIT No Attribution
3.17k stars 229 forks source link

C/C++ SettingsStore deleted #166

Open rblumenowgs opened 3 years ago

rblumenowgs commented 3 years ago

Happy to pay to get this bug fixed/fast-tracked :)

When opening PandasGUI, editing data, closing, and attempting to reopen, I get the following error:

RuntimeError: wrapped C/C++ object of type SettingsStore has been deleted Traceback: File "c:\users\ryan\appdata\local\programs\python\python39\lib\site-packages\streamlit\script_runner.py", line 350, in _run_script exec(code, module.dict) File "D:\Desktop\Jobs\Globalstratos\Frontend\GlobalstratosUI\app.py", line 42, in dashboard.run() File "D:\Desktop\Jobs\Globalstratos\Frontend\GlobalstratosUI\multipage2.py", line 138, in run page['function']() File "D:\Desktop\Jobs\Globalstratos\Frontend\GlobalstratosUI\DBsiteinfo.py", line 339, in siteinfo gui = show(sites_transposed = sites_transposed, settings={'block':True}) File "c:\users\ryan\appdata\local\programs\python\python39\lib\site-packages\pandasgui\gui.py", line 460, in show pandas_gui = PandasGui(settings=settings, **kwargs) File "c:\users\ryan\appdata\local\programs\python\python39\lib\site-packages\pandasgui\gui.py", line 73, in init self.init_ui() File "c:\users\ryan\appdata\local\programs\python\python39\lib\site-packages\pandasgui\gui.py", line 161, in init_ui self.store.settings.settingsChanged.connect(self.apply_settings)

adamerose commented 3 years ago

I've been unable to consistently reproduce this error so far, let me know if you can create a minimum reproducible example

This snippet runs with no errors:

from pandasgui import show
from pandasgui.datasets import pokemon

gui = show(pokemon, settings={'block':True})
# *Now I edit data and close the first GUI, then the 2nd one opens*
gui2 = show(pokemon, settings={'block':True})
rblumenowgs commented 3 years ago

Happy to jump on a call tomorrow - the bug actually happens every time for me, so it is very reproducible on my side 🙂


From: Adam Rose @.> Sent: 27 August 2021 16:09 To: adamerose/PandasGUI @.> Cc: Ryan Blumenow @.>; Author @.> Subject: Re: [adamerose/PandasGUI] C/C++ SettingsStore deleted (#166)

I've been unable to consistently reproduce this error so far, let me know if you can create a minimum reproducible example

This snippet runs with no errors:

from pandasgui import show from pandasgui.datasets import pokemon

gui = show(pokemon, settings={'block':True})

Now I edit data and close the first GUI, then the 2nd one opens

gui2 = show(pokemon, settings={'block':True})

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/adamerose/PandasGUI/issues/166#issuecomment-907231849, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AUQWHIVJCZHRQQQRJFSN573T66MBHANCNFSM5C4EIS7Q. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Disclaimers: 1) This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 2) Our company accepts no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 3) Our organization is NOT a Securities Dealer, Broker, or Investment Adviser. This email letter and attached related documents are never to be considered a solicitation for any purpose in any form or context. 4) Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Employees of the company are expressly required not to make defamatory statements and not to infringe or authorize any infringement of copyright or any other legal right by email communications. Any such communication is contrary to company policy and outside the scope of the employment of the individual concerned. The company will not accept any liability in respect of such communication, and the employee responsible will be personally liable for any damages or other liability arising. 5) No employee or agent is authorized to conclude any binding agreement on behalf of our organization with another party by email without express written confirmation by the Chairman of the Board of Directors. 6) WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments. 7) Any electronic communication that is conducted within or through the firm and its affiliate's systems will be subject to being archived, monitored and produced to regulators and in litigation in accordance with the firm and its affiliate's policies and local laws, rules, and regulations. Electronic communications may be archived in countries other than the country in which you are located, and may be treated in accordance with the laws and regulations of the country of each individual included in the entire message chain. Disclaimers: 1) This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 2) Our company accepts no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 3) Our organization is NOT a Securities Dealer, Broker, or Investment Adviser. This email letter and attached related documents are never to be considered a solicitation for any purpose in any form or context. 4) Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Employees of the company are expressly required not to make defamatory statements and not to infringe or authorize any infringement of copyright or any other legal right by email communications. Any such communication is contrary to company policy and outside the scope of the employment of the individual concerned. The company will not accept any liability in respect of such communication, and the employee responsible will be personally liable for any damages or other liability arising. 5) No employee or agent is authorized to conclude any binding agreement on behalf of our organization with another party by email without express written confirmation by the Chairman of the Board of Directors. 6) WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments. 7) Any electronic communication that is conducted within or through the firm and its affiliate's systems will be subject to being archived, monitored and produced to regulators and in litigation in accordance with the firm and its affiliate's policies and local laws, rules, and regulations. Electronic communications may be archived in countries other than the country in which you are located, and may be treated in accordance with the laws and regulations of the country of each individual included in the entire message chain.

rblumenowgs commented 3 years ago

The bug happens for me when I edit the data, then close the first GUI, and then try and reopen PandasGUI again.


From: Ryan Blumenow @.> Sent: 27 August 2021 16:59 To: adamerose/PandasGUI @.>; adamerose/PandasGUI @.> Cc: Author @.> Subject: Re: [adamerose/PandasGUI] C/C++ SettingsStore deleted (#166)

Happy to jump on a call tomorrow - the bug actually happens every time for me, so it is very reproducible on my side 🙂


From: Adam Rose @.> Sent: 27 August 2021 16:09 To: adamerose/PandasGUI @.> Cc: Ryan Blumenow @.>; Author @.> Subject: Re: [adamerose/PandasGUI] C/C++ SettingsStore deleted (#166)

I've been unable to consistently reproduce this error so far, let me know if you can create a minimum reproducible example

This snippet runs with no errors:

from pandasgui import show from pandasgui.datasets import pokemon

gui = show(pokemon, settings={'block':True})

Now I edit data and close the first GUI, then the 2nd one opens

gui2 = show(pokemon, settings={'block':True})

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/adamerose/PandasGUI/issues/166#issuecomment-907231849, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AUQWHIVJCZHRQQQRJFSN573T66MBHANCNFSM5C4EIS7Q. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Disclaimers: 1) This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 2) Our company accepts no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 3) Our organization is NOT a Securities Dealer, Broker, or Investment Adviser. This email letter and attached related documents are never to be considered a solicitation for any purpose in any form or context. 4) Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Employees of the company are expressly required not to make defamatory statements and not to infringe or authorize any infringement of copyright or any other legal right by email communications. Any such communication is contrary to company policy and outside the scope of the employment of the individual concerned. The company will not accept any liability in respect of such communication, and the employee responsible will be personally liable for any damages or other liability arising. 5) No employee or agent is authorized to conclude any binding agreement on behalf of our organization with another party by email without express written confirmation by the Chairman of the Board of Directors. 6) WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments. 7) Any electronic communication that is conducted within or through the firm and its affiliate's systems will be subject to being archived, monitored and produced to regulators and in litigation in accordance with the firm and its affiliate's policies and local laws, rules, and regulations. Electronic communications may be archived in countries other than the country in which you are located, and may be treated in accordance with the laws and regulations of the country of each individual included in the entire message chain. Disclaimers: 1) This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 2) Our company accepts no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 3) Our organization is NOT a Securities Dealer, Broker, or Investment Adviser. This email letter and attached related documents are never to be considered a solicitation for any purpose in any form or context. 4) Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Employees of the company are expressly required not to make defamatory statements and not to infringe or authorize any infringement of copyright or any other legal right by email communications. Any such communication is contrary to company policy and outside the scope of the employment of the individual concerned. The company will not accept any liability in respect of such communication, and the employee responsible will be personally liable for any damages or other liability arising. 5) No employee or agent is authorized to conclude any binding agreement on behalf of our organization with another party by email without express written confirmation by the Chairman of the Board of Directors. 6) WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments. 7) Any electronic communication that is conducted within or through the firm and its affiliate's systems will be subject to being archived, monitored and produced to regulators and in litigation in accordance with the firm and its affiliate's policies and local laws, rules, and regulations. Electronic communications may be archived in countries other than the country in which you are located, and may be treated in accordance with the laws and regulations of the country of each individual included in the entire message chain.

adamerose commented 3 years ago

The bug happens for me when I edit the data, then close the first GUI, and then try and reopen PandasGUI again.

This is what my snippet above does though, so there must be some other factor at play here (my snippet runs without error for me let me know if different on your end). We can set up a call in DMs but in the mean time try making a minimal example (throw the error using a sample dataset and include as little other code as possible)

rblumenowgs commented 3 years ago

Hi Adam,

Here we go :) Please run the following in a standalone file, I run it from within VS Code. Then click the button it brings up, close PandasGUI, and click the button again. This triggers the error I get from my side.

import streamlit
import streamlit as st
from pandasgui import show
import sys
from streamlit import cli as stcli
import pandas as pd

def mainprgm():
    data = pd.DataFrame([1, 2, 3, 4, 5])

    datagui = st.button("Click for data")

    if datagui == True:
        gui = show(data)

if __name__ == '__main__':
    if streamlit._is_running_with_streamlit:
        mainprgm()
    else:
        sys.argv = ["streamlit", "run", sys.argv[0]]
        sys.exit(stcli.main())
adamerose commented 3 years ago

This is a tricky bug related to running PyQt5 outside the main thread, which is what streamlit does. When I run your code on my machine it actually crashes completely before even showing a stack trace. If I modify yours to manually create a QApplication before mainprgm I get your error but it's not easily solvable it's basically saying C++ have been destroyed or are not available because they're only accessible from the main thread.

I'm not sure if it's possible to fix this... I'd need to have a method when called in a non-main thread to trigger a method to run in the main threads. Maybe there's some workaround to do that but not sure yet

rblumenowgs commented 3 years ago

Thanks Adam. Would really appreciate it if you could carry on investigations to see if we can solve this. It's important in our flow unfortunately.


From: Adam Rose @.> Sent: 30 August 2021 05:47 To: adamerose/PandasGUI @.> Cc: Ryan Blumenow @.>; Author @.> Subject: Re: [adamerose/PandasGUI] C/C++ SettingsStore deleted (#166)

This is a tricky bug related to running PyQt5 outside the main thread, which is what streamlit does. When I run your code on my machine it actually crashes completely before even showing a stack trace. If I modify yours to manually create a QApplication before mainprgm I get your error but it's not easily solvable it's basically saying C++ have been destroyed or are not available because they're only accessible from the main thread.

I'm not sure if it's possible to fix this... I'd need to have a method when called in a non-main thread to trigger a method to run in the main threads. Maybe there's some workaround to do that but not sure yet

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/adamerose/PandasGUI/issues/166#issuecomment-907991285, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AUQWHIWTILKW3QOZJURWRWLT7L5MXANCNFSM5C4EIS7Q. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Disclaimers: 1) This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 2) Our company accepts no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 3) Our organization is NOT a Securities Dealer, Broker, or Investment Adviser. This email letter and attached related documents are never to be considered a solicitation for any purpose in any form or context. 4) Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Employees of the company are expressly required not to make defamatory statements and not to infringe or authorize any infringement of copyright or any other legal right by email communications. Any such communication is contrary to company policy and outside the scope of the employment of the individual concerned. The company will not accept any liability in respect of such communication, and the employee responsible will be personally liable for any damages or other liability arising. 5) No employee or agent is authorized to conclude any binding agreement on behalf of our organization with another party by email without express written confirmation by the Chairman of the Board of Directors. 6) WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments. 7) Any electronic communication that is conducted within or through the firm and its affiliate's systems will be subject to being archived, monitored and produced to regulators and in litigation in accordance with the firm and its affiliate's policies and local laws, rules, and regulations. Electronic communications may be archived in countries other than the country in which you are located, and may be treated in accordance with the laws and regulations of the country of each individual included in the entire message chain. Disclaimers: 1) This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 2) Our company accepts no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 3) Our organization is NOT a Securities Dealer, Broker, or Investment Adviser. This email letter and attached related documents are never to be considered a solicitation for any purpose in any form or context. 4) Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Employees of the company are expressly required not to make defamatory statements and not to infringe or authorize any infringement of copyright or any other legal right by email communications. Any such communication is contrary to company policy and outside the scope of the employment of the individual concerned. The company will not accept any liability in respect of such communication, and the employee responsible will be personally liable for any damages or other liability arising. 5) No employee or agent is authorized to conclude any binding agreement on behalf of our organization with another party by email without express written confirmation by the Chairman of the Board of Directors. 6) WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments. 7) Any electronic communication that is conducted within or through the firm and its affiliate's systems will be subject to being archived, monitored and produced to regulators and in litigation in accordance with the firm and its affiliate's policies and local laws, rules, and regulations. Electronic communications may be archived in countries other than the country in which you are located, and may be treated in accordance with the laws and regulations of the country of each individual included in the entire message chain.

ecyoung3 commented 2 years ago

I managed to fix this by implementing a copy() method for SettingsStore that creates a new instance with all the same settings. I couldn't come up with a good way of transferring ownership of the SettingsStore (QObject) to the PandasGui, but simply creating a new instance seems to work. Implementation of SettingsStore.copy() method below:

def copy(self):
        """ 
        Create a copy of the settings with a new QObject. Intended as a workaround
        to this bug: https://github.com/adamerose/PandasGUI/issues/166
        """
        # Create new settings instance
        new_settings = SettingsStore()

        # Copy every attribute that's a Setting
        for attr, value in self.__dict__.items():
            if isinstance(value, Setting):
                setattr(new_settings, attr, value)

        return new_settings

I am not using streamlit but rather Spyder (version 5.0) and was encountering the same bug until implementing the above workaround. I added this at the end of the PandasGui init_ui definition:

        # Create a copy of the settings in case the SettingsStore reference has
        # been discarded by Qt prematurely
        # https://stackoverflow.com/a/17935694/10342097
        self.store.settings = self.store.settings.copy()

        # Signals
        self.store.settings.settingsChanged.connect(self.apply_settings)

        self.apply_settings()
PhilipDeegan commented 2 years ago

@ecyoung3 thanks!

chadkennedyonline commented 2 years ago

Should @ecyoung3's fix be added in via a PR?