Example #1
0
def raise_exception_on_not_ok_status():
  status = c_api_util.ScopedTFStatus()
  yield status.status
  if c_api.TF_GetCode(status) != 0:
    raise _make_specific_exception(
        None, None,
        compat.as_text(c_api.TF_Message(status)),
        c_api.TF_GetCode(status))
Example #2
0
def is_directory_v2(path):
    """Returns whether the path is a directory or not.

  Args:
    path: string, path to a potential directory

  Returns:
    True, if the path is a directory; False otherwise
  """
    status = c_api_util.ScopedTFStatus()
    return pywrap_tensorflow.IsDirectory(compat.as_bytes(path), status)
Example #3
0
def raise_exception_on_not_ok_status():
    status = c_api_util.ScopedTFStatus()
    yield status.status
    try:
        if c_api.TF_GetCode(status.status) != 0:
            raise _make_specific_exception(
                None, None, compat.as_text(c_api.TF_Message(status.status)),
                c_api.TF_GetCode(status.status))
    # Delete the underlying status object from memory otherwise it stays alive
    # as there is a reference to status from this from the traceback due to raise.
    finally:
        del status
Example #4
0
 def testInvalidDeviceNumber(self):
     opts = tf_session.TF_NewSessionOptions()
     with errors.raise_exception_on_not_ok_status() as status:
         c_session = tf_session.TF_NewSession(
             ops.get_default_graph()._c_graph, opts, status)
         raw_device_list = tf_session.TF_SessionListDevices(
             c_session, status)
     size = tf_session.TF_DeviceListCount(raw_device_list)
     # Test that invalid device numbers return -1 rather than a Swig-wrapped
     # pointer.
     status_no_exception = c_api_util.ScopedTFStatus()
     memory = tf_session.TF_DeviceListMemoryBytes(raw_device_list, size,
                                                  status_no_exception)
     self.assertEqual(memory, -1)
     tf_session.TF_DeleteDeviceList(raw_device_list)
     with errors.raise_exception_on_not_ok_status() as status:
         tf_session.TF_CloseSession(c_session, status)
Example #5
0
 def __enter__(self):
     self.status = c_api_util.ScopedTFStatus()
     return self.status.status