'verify if bloomberg-anywhere pdblp session is valid

I want to implement a check if import pdblp is active and if not exit the session.

I note from this link (Bloomberg Anywhere + pdblp or xbbg + not logged in) that a session:

  1. remains logged in for 3 days.
  2. is logged out if a session is opened on another pc.

Therefore, i want to implement a try-execpt block like this:

import pdblp


# check if connected
try:
    con = pdblp.BCon(timeout=5000)
    con.start()
except Exception as e:
    print('not logged in:', e)

my question is, would the above be sufficient to validate the connection ? (ie. would the above throw an error, e).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source