question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BrokenPipeError: [Errno 32] Broken pipe

See original GitHub issue

I have created a tensortrade.env.generic.environment.TradingEnv using tensortrade.env.default.create as follows:

env_train = default.create(
    action_scheme=action_scheme,
    reward_scheme=reward_scheme,
    portfolio=portfolio_train,
    feed=feed_train,
    window_size=10,
    renderer="screen-log",
    enable_logger=True
)

The above environment works fine as it is but my model: PPO utilizes the GPU only around 0-3 %. Therefore, I wanna create a vector environment consisting of multiple environments for multiprocessing, and this is how I do it:

from stable_baselines3.common.env_util import make_vec_env
vec_env_train = make_vec_env(env_train, n_envs=num_envs, seed=42, vec_env_cls=SubprocVecEnv)

That results in BrokenPipeError: [Errno 32] Broken pipe. The error has been discussed in 509 and according to that the above code should work.

Clarification: The error relates to SB3, not TensorTrade. The following is the complete trace of the error:

---------------------------------------------------------------------------
BrokenPipeError                           Traceback (most recent call last)
<ipython-input-13-3b5897de4e37> in <module>()
      3 from stable_baselines3.common.env_util import make_vec_env
      4 
----> 5 vec_env_train = make_vec_env(env, n_envs=4, seed=42, vec_env_cls=SubprocVecEnv)

4 frames
/usr/local/lib/python3.7/dist-packages/stable_baselines3/common/env_util.py in make_vec_env(env_id, n_envs, seed, start_index, monitor_dir, wrapper_class, env_kwargs, vec_env_cls, vec_env_kwargs, monitor_kwargs, wrapper_kwargs)
    103         vec_env_cls = DummyVecEnv
    104 
--> 105     return vec_env_cls([make_env(i + start_index) for i in range(n_envs)], **vec_env_kwargs)
    106 
    107 

/usr/local/lib/python3.7/dist-packages/stable_baselines3/common/vec_env/subproc_vec_env.py in __init__(self, env_fns, start_method)
    108             work_remote.close()
    109 
--> 110         self.remotes[0].send(("get_spaces", None))
    111         observation_space, action_space = self.remotes[0].recv()
    112         VecEnv.__init__(self, len(env_fns), observation_space, action_space)

/usr/lib/python3.7/multiprocessing/connection.py in send(self, obj)
    204         self._check_closed()
    205         self._check_writable()
--> 206         self._send_bytes(_ForkingPickler.dumps(obj))
    207 
    208     def recv_bytes(self, maxlength=None):

/usr/lib/python3.7/multiprocessing/connection.py in _send_bytes(self, buf)
    402             # Also note we want to avoid sending a 0-length buffer separately,
    403             # to avoid "broken pipe" errors if the other end closed the pipe.
--> 404             self._send(header + buf)
    405 
    406     def _recv_bytes(self, maxsize=None):

/usr/lib/python3.7/multiprocessing/connection.py in _send(self, buf, write)
    366         remaining = len(buf)
    367         while True:
--> 368             n = write(self._handle, buf)
    369             remaining -= n
    370             if remaining == 0:

BrokenPipeError: [Errno 32] Broken pipe

### Checklist

  • I have read the documentation (required)
  • I have checked that there is no similar issue in the repo (required)
  • I have checked my env using the env checker (required)
  • I have provided a minimal working example to reproduce the bug (required)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zeeshanalipanhwarcommented, Nov 3, 2021

It turns out the make_vec_env function takes env_id to be either str or Callable, not a gym.env as mentioned in its function details. The following code resolves the issue.

from stable_baselines3.common.env_util import make_vec_env
vec_env_train = make_vec_env(lambda:env_train, n_envs=num_envs, seed=42, vec_env_cls=SubprocVecEnv)
0reactions
araffincommented, Nov 3, 2021

The following code resolves the issue.

yes, although you should do that with a lambda… it will give the same env object instead of instantiating new ones for each env.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent errno 32 broken pipe? - python - Stack Overflow
The broken pipe error usually occurs if your request is blocked or takes too long and after request-side timeout, it'll close the connection...
Read more >
“[Errno 32] Broken pipe” in Python - LinuxPip
"Broken pipe" is essentially an IOError error (short for input/output error), which happened at the Linux system level. It usually occurs when ...
Read more >
Broken Pipe Error in Python - GeeksforGeeks
A broken Pipe Error is generally an Input/Output Error, which is occurred at the Linux System level. The error has occurred during the ......
Read more >
brokenpipeerror errno 32 broken pipe multiprocessing
I am frequently getting below BrokenPipeError: [Errno 32] Broken pipe error while processing the requests. How to resolve this issue?
Read more >
Broken Pipe Error in Python - Javatpoint
What causes "[Errno 32] Broken pipe" in Python? ... "Broken pipe" is usually considered an IOError (short for Input/Output Error) error, which occurred...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found