Esempio n. 1
0
 def _protocol_send(self, command, args=""):
     if self._closing_state:
         return Event()
     self.trace("_protocol_send %s %s" % (command, args))
     # Append command to pool
     # and send it to eventsocket
     _cmd_uuid = str(uuid1())
     _async_res = gevent.event.AsyncResult()
     with self._lock:
         self._commands_pool.append((_cmd_uuid, _async_res))
         self._send("%s %s" % (command, args))
     self.trace("_protocol_send %s wait ..." % command)
     _uuid, event = _async_res.get()
     if _cmd_uuid != _uuid:
         raise InternalSyncError("in _protocol_send")
     # Casts Event to appropriate event type :
     # Casts to ApiResponse, if event is api
     if command == 'api':
         event = ApiResponse.cast(event)
     # Casts to BgapiResponse, if event is bgapi
     elif command == "bgapi":
         event = BgapiResponse.cast(event)
     # Casts to CommandResponse by default
     else:
         event = CommandResponse.cast(event)
     self.trace("_protocol_send %s done" % command)
     return event
Esempio n. 2
0
 def _protocol_send(self, command, args=""):
     if self._closing_state:
         return Event()
     self.trace("_protocol_send %s %s" % (command, args))
     # Append command to pool
     # and send it to eventsocket
     _cmd_uuid = str(uuid1())
     _async_res = gevent.event.AsyncResult()
     with self._lock:
         self._commands_pool.append((_cmd_uuid, _async_res))
         self._send("%s %s" % (command, args))
     self.trace("_protocol_send %s wait ..." % command)
     _uuid, event = _async_res.get()
     if _cmd_uuid != _uuid:
         raise InternalSyncError("in _protocol_send")
     # Casts Event to appropriate event type :
     # Casts to ApiResponse, if event is api
     if command == 'api':
         event = ApiResponse.cast(event)
     # Casts to BgapiResponse, if event is bgapi
     elif command == "bgapi":
         event = BgapiResponse.cast(event)
     # Casts to CommandResponse by default
     else:
         event = CommandResponse.cast(event)
     self.trace("_protocol_send %s done" % command)
     return event
Esempio n. 3
0
 def _protocol_send(self, command, args=""):
     if self._closing_state:
         return Event()
     self._lock.acquire()
     try:
         self._send("%s %s" % (command, args))
         event = self._response_queue.get()
     finally:
         self._lock.release()
     # Casts Event to appropriate event type :
     # Casts to ApiResponse, if event is api
     if command == 'api':
         event = ApiResponse.cast(event)
     # Casts to BgapiResponse, if event is bgapi
     elif command == "bgapi":
         event = BgapiResponse.cast(event)
     # Casts to CommandResponse by default
     else:
         event = CommandResponse.cast(event)
     return event