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

logout error in destructor of my class #80

Open
nexgen opened this issue Dec 30, 2024 · 3 comments
Open

logout error in destructor of my class #80

nexgen opened this issue Dec 30, 2024 · 3 comments

Comments

@nexgen
Copy link

nexgen commented Dec 30, 2024

I have created a wrapper around python-fmrest where I have:

def init(self, fm_server_url, fm_user, fm_password, fm_db_name):
self.fms.login()

def del(self):
self.fms.logout()

I get this error:
Exception ignored in: <function FileMaker.del at 0x118b38ca0>
Traceback (most recent call last):
File "filemaker_utils.py", line 21, in del
File ".venv/lib/python3.10/site-packages/fmrest/server.py", line 217, in logout
File ".venv/lib/python3.10/site-packages/fmrest/server.py", line 925, in _call_filemaker
File ".venv/lib/python3.10/site-packages/fmrest/utils.py", line 14, in request
fmrest.exceptions.RequestException: Request error: import of time halted; None in sys.modules

@davidhamann
Copy link
Owner

It's an import error and hard to tell without seeing the full project. Maybe you have shadowed time in your project? Maybe a circular import?

If I see correctly, the exception is raised by the requests library and then re-raised by python-fmrest. time is not directly imported in the fmrest utils.

You could check what print(sys.modules.get("time")) returns for you. Maybe it's not <module 'time' (built-in)>?

@nexgen
Copy link
Author

nexgen commented Jan 3, 2025

Here is the simplified working code for you to replicate this problem.

class FileMaker:
    def __init__(self, fm_server_url, fm_user, fm_password, fm_db_name):
        layout = "GLOBAL"
        self.fms = fmrest.Server(
            fm_server_url,
            user=fm_user,
            password=fm_password,
            database=fm_db_name,
            layout=layout,
            verify_ssl=True,
            api_version="v1",
        )

        self.fms.login()

    def __del__(self):
        self.fms.logout()

fm_server_url = ""
fm_user = ""
fm_password = ""
fm_db_name = ""
fm = Filemaker(fm_server_url, fm_user, fm_password, fm_db_name)

@davidhamann
Copy link
Owner

I believe the issue is that you're calling the logout during shutdown of the interpreter when some imports have already been cleared (when __del__ is called).

I would suggest using the context manager of fmrest (or a context manager for your wrapper):

fms = fmrest.Server(...)
with fms:
    fms.login()
    # do stuff
# continue with other stuff

This would also handle the logout for you.

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

No branches or pull requests

2 participants