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

Session still persists after halting script or jupyter book #24

Closed
amircp opened this issue Jul 29, 2023 · 3 comments
Closed

Session still persists after halting script or jupyter book #24

amircp opened this issue Jul 29, 2023 · 3 comments

Comments

@amircp
Copy link

amircp commented Jul 29, 2023

Hello, I've noticed that when I don't use the logout method in my class or Jupyter Notebook, the session with the broker persists, and you cannot log in again. As a consequence, you have to wait until it expires (in my case, up to 5 hours).

This will fix it (inside the cTrader class)

    def __del__(self):
        self.logout()

(i've forked the repo and created a commit for it, if this is not the right approach i won't create the PR)

Cheers.

@traderpedroso
Copy link
Member

Hello, I've noticed that when I don't use the logout method in my class or Jupyter Notebook, the session with the broker persists, and you cannot log in again. As a consequence, you have to wait until it expires (in my case, up to 5 hours).

This will fix it (inside the cTrader class)

    def __del__(self):
        self.logout()

(i've forked the repo and created a commit for it, if this is not the right approach i won't create the PR)

Cheers.

Could you verify if the session persists even after invoking the api.logout() method?

checkConnection = api.isconnected()
print("Is Connected?: ", checkConnection)
time.sleep(1)

@amircp
Copy link
Author

amircp commented Aug 2, 2023

Could you verify if the session persists even after invoking the api.logout() method?

Hello!
Yeah! it works. The problem i was mentioning is related to halting unexpectedly the application, scenarios:

  • If i run the library using Jupyter notebook and by mistake re-run everything (without invoking the logout method) the last session will persist so you cannot connect again until the connection times out.
  • If i implement the library into my framework or any class and i stop the script (ctrl + c) or an unhandled exception is generated the session with the broker persists. (is like the broker keeps thinking the client is still there and keeps the tcp connection opened)

It makes sense?
so in order to avoid this behavior we run the logout method in del magic method. (the object destroy method)

I'm going to create a PR for this and let you decide to include it or not.

@traderpedroso
Copy link
Member

Could you verify if the session persists even after invoking the api.logout() method?

Hello! Yeah! it works. The problem i was mentioning is related to halting unexpectedly the application, scenarios:

  • If i run the library using Jupyter notebook and by mistake re-run everything (without invoking the logout method) the last session will persist so you cannot connect again until the connection times out.
  • If i implement the library into my framework or any class and i stop the script (ctrl + c) or an unhandled exception is generated the session with the broker persists. (is like the broker keeps thinking the client is still there and keeps the tcp connection opened)

It makes sense? so in order to avoid this behavior we run the logout method in del magic method. (the object destroy method)

I'm going to create a PR for this and let you decide to include it or not.
great thank 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