2828from tensorflow .python import pywrap_tensorflow
2929from tensorflow .python .framework import c_api_util
3030from tensorflow .python .framework import device as pydev
31- from tensorflow .python .framework import errors
3231from tensorflow .python .util import compat
3332from tensorflow .python .util import is_in_graph_mode
3433from tensorflow .python .util import tf_contextlib
@@ -224,24 +223,21 @@ def _initialize_handle_and_devices(self):
224223 assert self ._context_devices is None
225224 opts = pywrap_tensorflow .TFE_NewContextOptions ()
226225 try :
227- with errors .raise_exception_on_not_ok_status () as status :
228- if self ._config is not None :
229- config_str = self ._config .SerializeToString ()
230- pywrap_tensorflow .TFE_ContextOptionsSetConfig (
231- opts , config_str , len (config_str ), status )
232- if self ._device_policy is not None :
233- pywrap_tensorflow .TFE_ContextOptionsSetDevicePlacementPolicy (
234- opts , self ._device_policy )
235- if self ._execution_mode == ASYNC :
236- pywrap_tensorflow .TFE_ContextOptionsSetAsync (opts , True )
237- self ._context_handle = pywrap_tensorflow .TFE_NewContext (opts , status )
226+ if self ._config is not None :
227+ config_str = self ._config .SerializeToString ()
228+ pywrap_tensorflow .TFE_ContextOptionsSetConfig (opts , config_str )
229+ if self ._device_policy is not None :
230+ pywrap_tensorflow .TFE_ContextOptionsSetDevicePlacementPolicy (
231+ opts , self ._device_policy )
232+ if self ._execution_mode == ASYNC :
233+ pywrap_tensorflow .TFE_ContextOptionsSetAsync (opts , True )
234+ self ._context_handle = pywrap_tensorflow .TFE_NewContext (opts )
238235 finally :
239236 pywrap_tensorflow .TFE_DeleteContextOptions (opts )
240237 # Store list of devices
241238 self ._context_devices = []
242- with errors .raise_exception_on_not_ok_status () as status :
243- device_list = pywrap_tensorflow .TFE_ContextListDevices (
244- self ._context_handle , status )
239+ device_list = pywrap_tensorflow .TFE_ContextListDevices (
240+ self ._context_handle )
245241 try :
246242 self ._num_gpus = 0
247243 for i in range (pywrap_tensorflow .TF_DeviceListCount (device_list )):
@@ -412,9 +408,7 @@ def set_execution_mode(self, mode):
412408 if mode is None :
413409 mode = SYNC
414410 self ._eager_context .execution_mode = mode
415- with errors .raise_exception_on_not_ok_status () as status :
416- pywrap_tensorflow .TFE_ContextSetAsyncForThread (self ._handle ,
417- mode == ASYNC , status )
411+ pywrap_tensorflow .TFE_ContextSetAsyncForThread (self ._handle , mode == ASYNC )
418412
419413 @tf_contextlib .contextmanager
420414 def execution_mode (self , mode ):
@@ -428,8 +422,7 @@ def execution_mode(self, mode):
428422
429423 def async_wait (self ):
430424 """Waits for ops dispatched in ASYNC mode to finish."""
431- with errors .raise_exception_on_not_ok_status () as status :
432- pywrap_tensorflow .TFE_ContextAsyncWait (self ._handle , status )
425+ pywrap_tensorflow .TFE_ContextAsyncWait (self ._handle )
433426
434427 def async_clear_error (self ):
435428 """Clears errors raised during ASYNC execution."""
@@ -449,11 +442,9 @@ def add_function(self, fn):
449442 Args:
450443 fn: A wrapped TF_Function (returned from TF_GraphToFunction_wrapper).
451444 """
452- with errors .raise_exception_on_not_ok_status () as status :
453- pywrap_tensorflow .TFE_ContextAddFunction (
454- self ._handle , # pylint: disable=protected-access
455- fn ,
456- status )
445+ pywrap_tensorflow .TFE_ContextAddFunction (
446+ self ._handle , # pylint: disable=protected-access
447+ fn )
457448
458449 def add_function_def (self , fdef ):
459450 """Add a function definition to the context.
@@ -465,12 +456,10 @@ def add_function_def(self, fdef):
465456 fdef: A FunctionDef protocol buffer message.
466457 """
467458 fdef_string = fdef .SerializeToString ()
468- with errors .raise_exception_on_not_ok_status () as status :
469- pywrap_tensorflow .TFE_ContextAddFunctionDef (
470- self ._handle , # pylint: disable=protected-access
471- fdef_string ,
472- len (fdef_string ),
473- status )
459+ pywrap_tensorflow .TFE_ContextAddFunctionDef (
460+ self ._handle , # pylint: disable=protected-access
461+ fdef_string ,
462+ len (fdef_string ))
474463
475464 def add_post_execution_callback (self , callback ):
476465 """Add a post-execution callback to the context.
@@ -545,9 +534,8 @@ def export_run_metadata(self):
545534 if not self ._context_handle :
546535 return None
547536 with c_api_util .tf_buffer () as buffer_ :
548- with errors .raise_exception_on_not_ok_status () as status :
549- pywrap_tensorflow .TFE_ContextExportRunMetadata (
550- self ._context_handle , buffer_ , status )
537+ pywrap_tensorflow .TFE_ContextExportRunMetadata (
538+ self ._context_handle , buffer_ )
551539 proto_data = pywrap_tensorflow .TF_GetBuffer (buffer_ )
552540 run_metadata = config_pb2 .RunMetadata ()
553541 run_metadata .ParseFromString (compat .as_bytes (proto_data ))
0 commit comments