Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/tutorial_mnist_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import tensorflow as tf
import tensorlayer as tl

# set buffer mode to _IOLBF for stdout
tl.ops.setlinebuf()

# load environment for distributed training
task_spec = tl.distributed.TaskSpec()
Expand Down
4 changes: 0 additions & 4 deletions tensorlayer/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
import json
import time

# Disable buffer for stdout.
# When running in container, or other environments where stdout is redirected,
# the default buffer behavior will seriously delay the message written by `print`.
# sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)

class TaskSpecDef(object):
"""Specification for the distributed task with the job name, index of the task,
Expand Down
13 changes: 13 additions & 0 deletions tensorlayer/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,20 @@ def set_gpu_fraction(sess=None, gpu_fraction=0.3):
return sess


def setlinebuf():
"""Set buffer mode to _IOLBF for stdout.
When running in container, or other environments where stdout is redirected,
the default buffer behavior will seriously delay the message written by `print`.

TODO: this method should be called automatically by default.

References
-----------
- `<https://docs.python.org/2/library/functions.html#open>`_
- `<https://docs.python.org/3/library/functions.html#open>`_
- `man setlinebuf <https://linux.die.net/man/3/setlinebuf>`_
"""
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1)


def disable_print():
Expand Down