def main(): global options options = parseCmdLine() # Fill SessionOptions sessionOptions = blpapi.SessionOptions() sessionOptions.setServerHost(options.host) sessionOptions.setServerPort(options.port) sessionOptions.setSessionIdentityOptions(options.auth['option']) # Create an EventDispatcher with 2 processing threads dispatcher = blpapi.EventDispatcher(2) # Create a Session session = blpapi.Session(sessionOptions, processEvent, dispatcher) # Start dispatcher to "pump" the received events dispatcher.start() # Start session asynchronously if not session.startAsync(): raise Exception("Can't initiate session start.") # Sleep until application will be interrupted by user (Ctrl+C pressed) # or because of the exception in event handler try: # Note that: 'thread.interrupt_main()' could be used to # correctly stop the application from 'processEvent' while True: time.sleep(1) finally: session.stop() dispatcher.stop()
def __init__(self, handler=None): self.correlation_ids = defaultdict(dict) if handler is None: handler = br.processEvent self.event_handler = handler self.dispatcher = bb.EventDispatcher(10) super(Session, self).__init__(SESSION_OPTIONS, self.event_handler, self.dispatcher) self.dispatcher.start() self.started = False self.queue = Queue() self.subscription_list = bb.SubscriptionList() self.start_session()