We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Issues with ops.exit_tf function
So far I've 2 issues with this function :
- ops.exit_tf() returns an error because a session is expected as argument.
- ops.exit_tf(sess) returns "NameError: name 'exit' is not defined" when launched from an IPython console - in my case it's Spyder's internal IPython console (tested both on Mac and Windows)

Both issue are easy to solve :
- add `if sess != None:` before `sess.close()`
- use `from sys import exit as _exit` to avoid whatever is the interference that's throwing the error

Before I propose a pull request, I just wanted to check that I'm not misusing the function : I tried to use the function without an argument to easly exit tensorboard (which is a nice feature) and I'm launching it from IPyton instead of the terminal because it's seems like a usefull function to be able to include in a script (and i run my scripts from Spyder)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tensorlayer/ops.py`
Content:
```
1 #! /usr/bin/python
2 # -*- coding: utf8 -*-
3 
4 
5 
6 
7 import tensorflow as tf
8 import os
9 import sys
10 from sys import platform as _platform
11 
12 
13 def exit_tf(sess=None):
14     """Close tensorboard and nvidia-process if available
15 
16     Parameters
17     ----------
18     sess : a session instance of TensorFlow
19         TensorFlow session
20     """
21     text = "[tl] Close tensorboard and nvidia-process if available"
22     sess.close()
23     # import time
24     # time.sleep(2)
25     if _platform == "linux" or _platform == "linux2":
26         print('linux: %s' % text)
27         os.system('nvidia-smi')
28         os.system('fuser 6006/tcp -k')  # kill tensorboard 6006
29         os.system("nvidia-smi | grep python |awk '{print $3}'|xargs kill") # kill all nvidia-smi python process
30     elif _platform == "darwin":
31         print('OS X: %s' % text)
32         os.system("lsof -i tcp:6006 | grep -v PID | awk '{print $2}' | xargs kill") # kill tensorboard 6006
33     elif _platform == "win32":
34         print('Windows: %s' % text)
35     else:
36         print(_platform)
37     exit()
38 
39 def clear_all(printable=True):
40     """Clears all the placeholder variables of keep prob,
41     including keeping probabilities of all dropout, denoising, dropconnect etc.
42 
43     Parameters
44     ----------
45     printable : boolean
46         If True, print all deleted variables.
47     """
48     print('clear all .....................................')
49     gl = globals().copy()
50     for var in gl:
51         if var[0] == '_': continue
52         if 'func' in str(globals()[var]): continue
53         if 'module' in str(globals()[var]): continue
54         if 'class' in str(globals()[var]): continue
55 
56         if printable:
57             print(" clear_all ------- %s" % str(globals()[var]))
58 
59         del globals()[var]
60 
61 # def clear_all2(vars, printable=True):
62 #     """
63 #     The :function:`clear_all()` Clears all the placeholder variables of keep prob,
64 #     including keeping probabilities of all dropout, denoising, dropconnect
65 #     Parameters
66 #     ----------
67 #     printable : if True, print all deleted variables.
68 #     """
69 #     print('clear all .....................................')
70 #     for var in vars:
71 #         if var[0] == '_': continue
72 #         if 'func' in str(var): continue
73 #         if 'module' in str(var): continue
74 #         if 'class' in str(var): continue
75 #
76 #         if printable:
77 #             print(" clear_all ------- %s" % str(var))
78 #
79 #         del var
80 
81 def set_gpu_fraction(sess=None, gpu_fraction=0.3):
82     """Set the GPU memory fraction for the application.
83 
84     Parameters
85     ----------
86     sess : a session instance of TensorFlow
87         TensorFlow session
88     gpu_fraction : a float
89         Fraction of GPU memory, (0 ~ 1]
90 
91     References
92     ----------
93     - `TensorFlow using GPU <https://www.tensorflow.org/versions/r0.9/how_tos/using_gpu/index.html>`_
94     """
95     print("  tensorlayer: GPU MEM Fraction %f" % gpu_fraction)
96     gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_fraction)
97     sess = tf.Session(config = tf.ConfigProto(gpu_options = gpu_options))
98     return sess
99 
100 
101 
102 
103 
104 def disable_print():
105     """Disable console output, ``suppress_stdout`` is recommended.
106 
107     Examples
108     ---------
109     >>> print("You can see me")
110     >>> tl.ops.disable_print()
111     >>> print(" You can't see me")
112     >>> tl.ops.enable_print()
113     >>> print("You can see me")
114     """
115     # sys.stdout = os.devnull   # this one kill the process
116     sys.stdout = None
117     sys.stderr = os.devnull
118 
119 def enable_print():
120     """Enable console output, ``suppress_stdout`` is recommended.
121 
122     Examples
123     --------
124     - see tl.ops.disable_print()
125     """
126     sys.stdout = sys.__stdout__
127     sys.stderr = sys.__stderr__
128 
129 
130 # class temporary_disable_print:
131 #     """Temporarily disable console output.
132 #
133 #     Examples
134 #     ---------
135 #     >>> print("You can see me")
136 #     >>> with tl.ops.temporary_disable_print() as t:
137 #     >>>     print("You can't see me")
138 #     >>> print("You can see me")
139 #     """
140 #     def __init__(self):
141 #         pass
142 #     def __enter__(self):
143 #         sys.stdout = None
144 #         sys.stderr = os.devnull
145 #     def __exit__(self, type, value, traceback):
146 #         sys.stdout = sys.__stdout__
147 #         sys.stderr = sys.__stderr__
148 #         return isinstance(value, TypeError)
149 
150 
151 from contextlib import contextmanager
152 @contextmanager
153 def suppress_stdout():
154     """Temporarily disable console output.
155 
156     Examples
157     ---------
158     >>> print("You can see me")
159     >>> with tl.ops.suppress_stdout():
160     >>>     print("You can't see me")
161     >>> print("You can see me")
162 
163     References
164     -----------
165     - `stackoverflow <http://stackoverflow.com/questions/2125702/how-to-suppress-console-output-in-python>`_
166     """
167     with open(os.devnull, "w") as devnull:
168         old_stdout = sys.stdout
169         sys.stdout = devnull
170         try:
171             yield
172         finally:
173             sys.stdout = old_stdout
174 
175 
176 
177 def get_site_packages_directory():
178     """Print and return the site-packages directory.
179 
180     Examples
181     ---------
182     >>> loc = tl.ops.get_site_packages_directory()
183     """
184     import site
185     try:
186         loc = site.getsitepackages()
187         print("  tl.ops : site-packages in ", loc)
188         return loc
189     except:
190         print("  tl.ops : Cannot find package dir from virtual environment")
191         return False
192 
193 
194 
195 def empty_trash():
196     """Empty trash folder.
197 
198     """
199     text = "[tl] Empty the trash"
200     if _platform == "linux" or _platform == "linux2":
201         print('linux: %s' % text)
202         os.system("rm -rf ~/.local/share/Trash/*")
203     elif _platform == "darwin":
204         print('OS X: %s' % text)
205         os.system("sudo rm -rf ~/.Trash/*")
206     elif _platform == "win32":
207         print('Windows: %s' % text)
208         try:
209             os.system("rd /s c:\$Recycle.Bin")  # Windows 7 or Server 2008
210         except:
211             pass
212         try:
213             os.system("rd /s c:\recycler")  #  Windows XP, Vista, or Server 2003
214         except:
215             pass
216     else:
217         print(_platform)
218 
219 #
220
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/tensorlayer/ops.py b/tensorlayer/ops.py
--- a/tensorlayer/ops.py
+++ b/tensorlayer/ops.py
@@ -5,36 +5,73 @@
 
 
 import tensorflow as tf
+import tensorlayer as tl
 import os
+import subprocess
 import sys
 from sys import platform as _platform
+from sys import exit as _exit
 
 
-def exit_tf(sess=None):
-    """Close tensorboard and nvidia-process if available
+def exit_tf(sess=None, port=6006):
+    """Close tensorflow session, tensorboard and nvidia-process if available
 
     Parameters
     ----------
     sess : a session instance of TensorFlow
         TensorFlow session
+    tb_port : an integer
+        TensorBoard port you want to close, 6006 is tensorboard default
     """
     text = "[tl] Close tensorboard and nvidia-process if available"
-    sess.close()
+    text2 = "[tl] Close tensorboard and nvidia-process not yet supported by this function (tl.ops.exit_tf) on "
+    if sess != None:
+        sess.close()
     # import time
     # time.sleep(2)
     if _platform == "linux" or _platform == "linux2":
         print('linux: %s' % text)
         os.system('nvidia-smi')
-        os.system('fuser 6006/tcp -k')  # kill tensorboard 6006
+        os.system('fuser '+ port +'/tcp -k')  # kill tensorboard 6006
         os.system("nvidia-smi | grep python |awk '{print $3}'|xargs kill") # kill all nvidia-smi python process
+        _exit()
     elif _platform == "darwin":
         print('OS X: %s' % text)
-        os.system("lsof -i tcp:6006 | grep -v PID | awk '{print $2}' | xargs kill") # kill tensorboard 6006
+        subprocess.Popen("lsof -i tcp:"+ str(port) +"  | grep -v PID | awk '{print $2}' | xargs kill", shell=True) # kill tensorboard
     elif _platform == "win32":
-        print('Windows: %s' % text)
+        print(text2 + "Windows")
+        # TODO
     else:
-        print(_platform)
-    exit()
+        print(text2 + _platform)
+    
+def open_tb(logdir='/tmp/tensorflow', port=6006):
+    """Open tensorboard
+    
+    Parameters
+    ----------
+    logdir : a string
+        Directory where your tensorboard logs are saved
+    port : an integer
+        TensorBoard port you want to open, 6006 is tensorboard default
+    """
+
+    text = "[tl] Open tensorboard, go to localhost:" + str(port) + " to access"
+    text2 = " not yet supported by this function (tl.ops.open_tb)"
+    
+    if not tl.files.exists_or_mkdir(logdir, verbose=False):
+        print("[tl] Log reportory was created at %s" % logdir)
+    
+    if _platform == "linux" or _platform == "linux2":
+        print('linux %s' % text2)
+        # TODO
+    elif _platform == "darwin":
+        print('OS X: %s' % text)
+        subprocess.Popen(sys.prefix + " | python -m tensorflow.tensorboard --logdir=" + logdir + " --port=" + str(port), shell=True) # open tensorboard in localhost:6006/ or whatever port you chose
+    elif _platform == "win32":
+        print('Windows%s' % text2)
+        # TODO
+    else:
+        print(_platform + text2)
 
 def clear_all(printable=True):
     """Clears all the placeholder variables of keep prob,

{"golden_diff": "diff --git a/tensorlayer/ops.py b/tensorlayer/ops.py\n--- a/tensorlayer/ops.py\n+++ b/tensorlayer/ops.py\n@@ -5,36 +5,73 @@\n \n \n import tensorflow as tf\n+import tensorlayer as tl\n import os\n+import subprocess\n import sys\n from sys import platform as _platform\n+from sys import exit as _exit\n \n \n-def exit_tf(sess=None):\n-    \"\"\"Close tensorboard and nvidia-process if available\n+def exit_tf(sess=None, port=6006):\n+    \"\"\"Close tensorflow session, tensorboard and nvidia-process if available\n \n     Parameters\n     ----------\n     sess : a session instance of TensorFlow\n         TensorFlow session\n+    tb_port : an integer\n+        TensorBoard port you want to close, 6006 is tensorboard default\n     \"\"\"\n     text = \"[tl] Close tensorboard and nvidia-process if available\"\n-    sess.close()\n+    text2 = \"[tl] Close tensorboard and nvidia-process not yet supported by this function (tl.ops.exit_tf) on \"\n+    if sess != None:\n+        sess.close()\n     # import time\n     # time.sleep(2)\n     if _platform == \"linux\" or _platform == \"linux2\":\n         print('linux: %s' % text)\n         os.system('nvidia-smi')\n-        os.system('fuser 6006/tcp -k')  # kill tensorboard 6006\n+        os.system('fuser '+ port +'/tcp -k')  # kill tensorboard 6006\n         os.system(\"nvidia-smi | grep python |awk '{print $3}'|xargs kill\") # kill all nvidia-smi python process\n+        _exit()\n     elif _platform == \"darwin\":\n         print('OS X: %s' % text)\n-        os.system(\"lsof -i tcp:6006 | grep -v PID | awk '{print $2}' | xargs kill\") # kill tensorboard 6006\n+        subprocess.Popen(\"lsof -i tcp:\"+ str(port) +\"  | grep -v PID | awk '{print $2}' | xargs kill\", shell=True) # kill tensorboard\n     elif _platform == \"win32\":\n-        print('Windows: %s' % text)\n+        print(text2 + \"Windows\")\n+        # TODO\n     else:\n-        print(_platform)\n-    exit()\n+        print(text2 + _platform)\n+    \n+def open_tb(logdir='/tmp/tensorflow', port=6006):\n+    \"\"\"Open tensorboard\n+    \n+    Parameters\n+    ----------\n+    logdir : a string\n+        Directory where your tensorboard logs are saved\n+    port : an integer\n+        TensorBoard port you want to open, 6006 is tensorboard default\n+    \"\"\"\n+\n+    text = \"[tl] Open tensorboard, go to localhost:\" + str(port) + \" to access\"\n+    text2 = \" not yet supported by this function (tl.ops.open_tb)\"\n+    \n+    if not tl.files.exists_or_mkdir(logdir, verbose=False):\n+        print(\"[tl] Log reportory was created at %s\" % logdir)\n+    \n+    if _platform == \"linux\" or _platform == \"linux2\":\n+        print('linux %s' % text2)\n+        # TODO\n+    elif _platform == \"darwin\":\n+        print('OS X: %s' % text)\n+        subprocess.Popen(sys.prefix + \" | python -m tensorflow.tensorboard --logdir=\" + logdir + \" --port=\" + str(port), shell=True) # open tensorboard in localhost:6006/ or whatever port you chose\n+    elif _platform == \"win32\":\n+        print('Windows%s' % text2)\n+        # TODO\n+    else:\n+        print(_platform + text2)\n \n def clear_all(printable=True):\n     \"\"\"Clears all the placeholder variables of keep prob,\n", "issue": "Issues with ops.exit_tf function\nSo far I've 2 issues with this function :\r\n- ops.exit_tf() returns an error because a session is expected as argument.\r\n- ops.exit_tf(sess) returns \"NameError: name 'exit' is not defined\" when launched from an IPython console - in my case it's Spyder's internal IPython console (tested both on Mac and Windows)\r\n\r\nBoth issue are easy to solve :\r\n- add `if sess != None:` before `sess.close()`\r\n- use `from sys import exit as _exit` to avoid whatever is the interference that's throwing the error\r\n\r\nBefore I propose a pull request, I just wanted to check that I'm not misusing the function : I tried to use the function without an argument to easly exit tensorboard (which is a nice feature) and I'm launching it from IPyton instead of the terminal because it's seems like a usefull function to be able to include in a script (and i run my scripts from Spyder)\n", "before_files": [{"content": "#! /usr/bin/python\n# -*- coding: utf8 -*-\n\n\n\n\nimport tensorflow as tf\nimport os\nimport sys\nfrom sys import platform as _platform\n\n\ndef exit_tf(sess=None):\n    \"\"\"Close tensorboard and nvidia-process if available\n\n    Parameters\n    ----------\n    sess : a session instance of TensorFlow\n        TensorFlow session\n    \"\"\"\n    text = \"[tl] Close tensorboard and nvidia-process if available\"\n    sess.close()\n    # import time\n    # time.sleep(2)\n    if _platform == \"linux\" or _platform == \"linux2\":\n        print('linux: %s' % text)\n        os.system('nvidia-smi')\n        os.system('fuser 6006/tcp -k')  # kill tensorboard 6006\n        os.system(\"nvidia-smi | grep python |awk '{print $3}'|xargs kill\") # kill all nvidia-smi python process\n    elif _platform == \"darwin\":\n        print('OS X: %s' % text)\n        os.system(\"lsof -i tcp:6006 | grep -v PID | awk '{print $2}' | xargs kill\") # kill tensorboard 6006\n    elif _platform == \"win32\":\n        print('Windows: %s' % text)\n    else:\n        print(_platform)\n    exit()\n\ndef clear_all(printable=True):\n    \"\"\"Clears all the placeholder variables of keep prob,\n    including keeping probabilities of all dropout, denoising, dropconnect etc.\n\n    Parameters\n    ----------\n    printable : boolean\n        If True, print all deleted variables.\n    \"\"\"\n    print('clear all .....................................')\n    gl = globals().copy()\n    for var in gl:\n        if var[0] == '_': continue\n        if 'func' in str(globals()[var]): continue\n        if 'module' in str(globals()[var]): continue\n        if 'class' in str(globals()[var]): continue\n\n        if printable:\n            print(\" clear_all ------- %s\" % str(globals()[var]))\n\n        del globals()[var]\n\n# def clear_all2(vars, printable=True):\n#     \"\"\"\n#     The :function:`clear_all()` Clears all the placeholder variables of keep prob,\n#     including keeping probabilities of all dropout, denoising, dropconnect\n#     Parameters\n#     ----------\n#     printable : if True, print all deleted variables.\n#     \"\"\"\n#     print('clear all .....................................')\n#     for var in vars:\n#         if var[0] == '_': continue\n#         if 'func' in str(var): continue\n#         if 'module' in str(var): continue\n#         if 'class' in str(var): continue\n#\n#         if printable:\n#             print(\" clear_all ------- %s\" % str(var))\n#\n#         del var\n\ndef set_gpu_fraction(sess=None, gpu_fraction=0.3):\n    \"\"\"Set the GPU memory fraction for the application.\n\n    Parameters\n    ----------\n    sess : a session instance of TensorFlow\n        TensorFlow session\n    gpu_fraction : a float\n        Fraction of GPU memory, (0 ~ 1]\n\n    References\n    ----------\n    - `TensorFlow using GPU <https://www.tensorflow.org/versions/r0.9/how_tos/using_gpu/index.html>`_\n    \"\"\"\n    print(\"  tensorlayer: GPU MEM Fraction %f\" % gpu_fraction)\n    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_fraction)\n    sess = tf.Session(config = tf.ConfigProto(gpu_options = gpu_options))\n    return sess\n\n\n\n\n\ndef disable_print():\n    \"\"\"Disable console output, ``suppress_stdout`` is recommended.\n\n    Examples\n    ---------\n    >>> print(\"You can see me\")\n    >>> tl.ops.disable_print()\n    >>> print(\" You can't see me\")\n    >>> tl.ops.enable_print()\n    >>> print(\"You can see me\")\n    \"\"\"\n    # sys.stdout = os.devnull   # this one kill the process\n    sys.stdout = None\n    sys.stderr = os.devnull\n\ndef enable_print():\n    \"\"\"Enable console output, ``suppress_stdout`` is recommended.\n\n    Examples\n    --------\n    - see tl.ops.disable_print()\n    \"\"\"\n    sys.stdout = sys.__stdout__\n    sys.stderr = sys.__stderr__\n\n\n# class temporary_disable_print:\n#     \"\"\"Temporarily disable console output.\n#\n#     Examples\n#     ---------\n#     >>> print(\"You can see me\")\n#     >>> with tl.ops.temporary_disable_print() as t:\n#     >>>     print(\"You can't see me\")\n#     >>> print(\"You can see me\")\n#     \"\"\"\n#     def __init__(self):\n#         pass\n#     def __enter__(self):\n#         sys.stdout = None\n#         sys.stderr = os.devnull\n#     def __exit__(self, type, value, traceback):\n#         sys.stdout = sys.__stdout__\n#         sys.stderr = sys.__stderr__\n#         return isinstance(value, TypeError)\n\n\nfrom contextlib import contextmanager\n@contextmanager\ndef suppress_stdout():\n    \"\"\"Temporarily disable console output.\n\n    Examples\n    ---------\n    >>> print(\"You can see me\")\n    >>> with tl.ops.suppress_stdout():\n    >>>     print(\"You can't see me\")\n    >>> print(\"You can see me\")\n\n    References\n    -----------\n    - `stackoverflow <http://stackoverflow.com/questions/2125702/how-to-suppress-console-output-in-python>`_\n    \"\"\"\n    with open(os.devnull, \"w\") as devnull:\n        old_stdout = sys.stdout\n        sys.stdout = devnull\n        try:\n            yield\n        finally:\n            sys.stdout = old_stdout\n\n\n\ndef get_site_packages_directory():\n    \"\"\"Print and return the site-packages directory.\n\n    Examples\n    ---------\n    >>> loc = tl.ops.get_site_packages_directory()\n    \"\"\"\n    import site\n    try:\n        loc = site.getsitepackages()\n        print(\"  tl.ops : site-packages in \", loc)\n        return loc\n    except:\n        print(\"  tl.ops : Cannot find package dir from virtual environment\")\n        return False\n\n\n\ndef empty_trash():\n    \"\"\"Empty trash folder.\n\n    \"\"\"\n    text = \"[tl] Empty the trash\"\n    if _platform == \"linux\" or _platform == \"linux2\":\n        print('linux: %s' % text)\n        os.system(\"rm -rf ~/.local/share/Trash/*\")\n    elif _platform == \"darwin\":\n        print('OS X: %s' % text)\n        os.system(\"sudo rm -rf ~/.Trash/*\")\n    elif _platform == \"win32\":\n        print('Windows: %s' % text)\n        try:\n            os.system(\"rd /s c:\\$Recycle.Bin\")  # Windows 7 or Server 2008\n        except:\n            pass\n        try:\n            os.system(\"rd /s c:\\recycler\")  #  Windows XP, Vista, or Server 2003\n        except:\n            pass\n    else:\n        print(_platform)\n\n#\n", "path": "tensorlayer/ops.py"}], "after_files": [{"content": "#! /usr/bin/python\n# -*- coding: utf8 -*-\n\n\n\n\nimport tensorflow as tf\nimport tensorlayer as tl\nimport os\nimport subprocess\nimport sys\nfrom sys import platform as _platform\nfrom sys import exit as _exit\n\n\ndef exit_tf(sess=None, port=6006):\n    \"\"\"Close tensorflow session, tensorboard and nvidia-process if available\n\n    Parameters\n    ----------\n    sess : a session instance of TensorFlow\n        TensorFlow session\n    tb_port : an integer\n        TensorBoard port you want to close, 6006 is tensorboard default\n    \"\"\"\n    text = \"[tl] Close tensorboard and nvidia-process if available\"\n    text2 = \"[tl] Close tensorboard and nvidia-process not yet supported by this function (tl.ops.exit_tf) on \"\n    if sess != None:\n        sess.close()\n    # import time\n    # time.sleep(2)\n    if _platform == \"linux\" or _platform == \"linux2\":\n        print('linux: %s' % text)\n        os.system('nvidia-smi')\n        os.system('fuser '+ port +'/tcp -k')  # kill tensorboard 6006\n        os.system(\"nvidia-smi | grep python |awk '{print $3}'|xargs kill\") # kill all nvidia-smi python process\n        _exit()\n    elif _platform == \"darwin\":\n        print('OS X: %s' % text)\n        subprocess.Popen(\"lsof -i tcp:\"+ str(port) +\"  | grep -v PID | awk '{print $2}' | xargs kill\", shell=True) # kill tensorboard\n    elif _platform == \"win32\":\n        print(text2 + \"Windows\")\n        # TODO\n    else:\n        print(text2 + _platform)\n    \ndef open_tb(logdir='/tmp/tensorflow', port=6006):\n    \"\"\"Open tensorboard\n    \n    Parameters\n    ----------\n    logdir : a string\n        Directory where your tensorboard logs are saved\n    port : an integer\n        TensorBoard port you want to open, 6006 is tensorboard default\n    \"\"\"\n\n    text = \"[tl] Open tensorboard, go to localhost:\" + str(port) + \" to access\"\n    text2 = \" not yet supported by this function (tl.ops.open_tb)\"\n    \n    if not tl.files.exists_or_mkdir(logdir, verbose=False):\n        print(\"[tl] Log reportory was created at %s\" % logdir)\n    \n    if _platform == \"linux\" or _platform == \"linux2\":\n        print('linux %s' % text2)\n        # TODO\n    elif _platform == \"darwin\":\n        print('OS X: %s' % text)\n        subprocess.Popen(sys.prefix + \" | python -m tensorflow.tensorboard --logdir=\" + logdir + \" --port=\" + str(port), shell=True) # open tensorboard in localhost:6006/ or whatever port you chose\n    elif _platform == \"win32\":\n        print('Windows%s' % text2)\n        # TODO\n    else:\n        print(_platform + text2)\n\ndef clear_all(printable=True):\n    \"\"\"Clears all the placeholder variables of keep prob,\n    including keeping probabilities of all dropout, denoising, dropconnect etc.\n\n    Parameters\n    ----------\n    printable : boolean\n        If True, print all deleted variables.\n    \"\"\"\n    print('clear all .....................................')\n    gl = globals().copy()\n    for var in gl:\n        if var[0] == '_': continue\n        if 'func' in str(globals()[var]): continue\n        if 'module' in str(globals()[var]): continue\n        if 'class' in str(globals()[var]): continue\n\n        if printable:\n            print(\" clear_all ------- %s\" % str(globals()[var]))\n\n        del globals()[var]\n\n# def clear_all2(vars, printable=True):\n#     \"\"\"\n#     The :function:`clear_all()` Clears all the placeholder variables of keep prob,\n#     including keeping probabilities of all dropout, denoising, dropconnect\n#     Parameters\n#     ----------\n#     printable : if True, print all deleted variables.\n#     \"\"\"\n#     print('clear all .....................................')\n#     for var in vars:\n#         if var[0] == '_': continue\n#         if 'func' in str(var): continue\n#         if 'module' in str(var): continue\n#         if 'class' in str(var): continue\n#\n#         if printable:\n#             print(\" clear_all ------- %s\" % str(var))\n#\n#         del var\n\ndef set_gpu_fraction(sess=None, gpu_fraction=0.3):\n    \"\"\"Set the GPU memory fraction for the application.\n\n    Parameters\n    ----------\n    sess : a session instance of TensorFlow\n        TensorFlow session\n    gpu_fraction : a float\n        Fraction of GPU memory, (0 ~ 1]\n\n    References\n    ----------\n    - `TensorFlow using GPU <https://www.tensorflow.org/versions/r0.9/how_tos/using_gpu/index.html>`_\n    \"\"\"\n    print(\"  tensorlayer: GPU MEM Fraction %f\" % gpu_fraction)\n    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_fraction)\n    sess = tf.Session(config = tf.ConfigProto(gpu_options = gpu_options))\n    return sess\n\n\n\n\n\ndef disable_print():\n    \"\"\"Disable console output, ``suppress_stdout`` is recommended.\n\n    Examples\n    ---------\n    >>> print(\"You can see me\")\n    >>> tl.ops.disable_print()\n    >>> print(\" You can't see me\")\n    >>> tl.ops.enable_print()\n    >>> print(\"You can see me\")\n    \"\"\"\n    # sys.stdout = os.devnull   # this one kill the process\n    sys.stdout = None\n    sys.stderr = os.devnull\n\ndef enable_print():\n    \"\"\"Enable console output, ``suppress_stdout`` is recommended.\n\n    Examples\n    --------\n    - see tl.ops.disable_print()\n    \"\"\"\n    sys.stdout = sys.__stdout__\n    sys.stderr = sys.__stderr__\n\n\n# class temporary_disable_print:\n#     \"\"\"Temporarily disable console output.\n#\n#     Examples\n#     ---------\n#     >>> print(\"You can see me\")\n#     >>> with tl.ops.temporary_disable_print() as t:\n#     >>>     print(\"You can't see me\")\n#     >>> print(\"You can see me\")\n#     \"\"\"\n#     def __init__(self):\n#         pass\n#     def __enter__(self):\n#         sys.stdout = None\n#         sys.stderr = os.devnull\n#     def __exit__(self, type, value, traceback):\n#         sys.stdout = sys.__stdout__\n#         sys.stderr = sys.__stderr__\n#         return isinstance(value, TypeError)\n\n\nfrom contextlib import contextmanager\n@contextmanager\ndef suppress_stdout():\n    \"\"\"Temporarily disable console output.\n\n    Examples\n    ---------\n    >>> print(\"You can see me\")\n    >>> with tl.ops.suppress_stdout():\n    >>>     print(\"You can't see me\")\n    >>> print(\"You can see me\")\n\n    References\n    -----------\n    - `stackoverflow <http://stackoverflow.com/questions/2125702/how-to-suppress-console-output-in-python>`_\n    \"\"\"\n    with open(os.devnull, \"w\") as devnull:\n        old_stdout = sys.stdout\n        sys.stdout = devnull\n        try:\n            yield\n        finally:\n            sys.stdout = old_stdout\n\n\n\ndef get_site_packages_directory():\n    \"\"\"Print and return the site-packages directory.\n\n    Examples\n    ---------\n    >>> loc = tl.ops.get_site_packages_directory()\n    \"\"\"\n    import site\n    try:\n        loc = site.getsitepackages()\n        print(\"  tl.ops : site-packages in \", loc)\n        return loc\n    except:\n        print(\"  tl.ops : Cannot find package dir from virtual environment\")\n        return False\n\n\n\ndef empty_trash():\n    \"\"\"Empty trash folder.\n\n    \"\"\"\n    text = \"[tl] Empty the trash\"\n    if _platform == \"linux\" or _platform == \"linux2\":\n        print('linux: %s' % text)\n        os.system(\"rm -rf ~/.local/share/Trash/*\")\n    elif _platform == \"darwin\":\n        print('OS X: %s' % text)\n        os.system(\"sudo rm -rf ~/.Trash/*\")\n    elif _platform == \"win32\":\n        print('Windows: %s' % text)\n        try:\n            os.system(\"rd /s c:\\$Recycle.Bin\")  # Windows 7 or Server 2008\n        except:\n            pass\n        try:\n            os.system(\"rd /s c:\\recycler\")  #  Windows XP, Vista, or Server 2003\n        except:\n            pass\n    else:\n        print(_platform)\n\n#\n", "path": "tensorlayer/ops.py"}]}