Fixes memory leak in py_func when functions return unwrapped strings.

PiperOrigin-RevId: 158046530
This commit is contained in:
Alexandre Passos 2017-06-05 12:27:49 -07:00 committed by TensorFlower Gardener
parent cf238e1f2f
commit 27f1b80c22

View File

@ -26,6 +26,7 @@ from __future__ import print_function
import threading
import numpy as np
import six
from tensorflow.python import pywrap_tensorflow
from tensorflow.python.framework import function
@ -81,6 +82,10 @@ class FuncRegistry(object):
if func is None:
raise ValueError("callback %s is not found" % token)
ret = func(*args)
# Strings seem to lead to a memory leak here if they're not wrapped in a
# list.
if isinstance(ret, six.binary_type):
ret = [ret]
# Ensures that we return either a single numpy array or a list of numpy
# arrays.
if isinstance(ret, (tuple, list)):