# Using evaluation with ExternalEnv

**URL:** <https://discuss.ray.io/t/using-evaluation-with-externalenv/3699>\
**Category:** RLlib\
**Created:** [October 1, 2021, 8:22pm UTC](https://discuss.ray.io/t/using-evaluation-with-externalenv/3699 "2021-10-01T20:22:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarshp](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/utkarshp/32/1564_2.png) [@utkarshp](https://discuss.ray.io/u/utkarshp)\
**Post date:** [October 1, 2021, 8:22pm UTC](https://discuss.ray.io/t/using-evaluation-with-externalenv/3699/1 "2021-10-01T20:22:58Z")

</div>

I am new to RLLib and Ray. I have a simulation environment that must be stepped independent of RLLib. I have implemented it by inheriting from ExternalEnv. In the beginning I determine when an episode should be started. When it does, I call start\_episode, then periodically call get\_action and log\_rewards as needed and finally call end\_episode with that episode id. Multiple episodes can be ongoing at the same time. So far, so good. Now, I need to evaluate the trained policy at episodes that start at fixed times.

To accomplish this, I enabled evaluation from the config. It initialized the environment in a separate thread, and immediately called “run” on it. Since I have the episode start times predetermined, the start\_episode and get\_action calls happened before the trainer completed enough training to start evaluation. Naturally, this caused the eval worker to crash with queue.\_Empty exception.

My question is, what is the best way to do this. One workaround would be to catch the exception, wait and retry. Is there a better way? Ideally, I would like to call “run” on my ExternalEnv only after evaluation has been started by the trainer process, and do this repeatedly whenever it needs to evaluate.

---

<div class="post-metadata">

**Author:** ![gjoliver](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/gjoliver/32/1490_2.png) [@gjoliver](https://discuss.ray.io/u/gjoliver)\
**Post date:** [October 5, 2021, 8:48am UTC](https://discuss.ray.io/t/using-evaluation-with-externalenv/3699/2 "2021-10-05T08:48:37Z")

</div>

Not sure what exactly is the queue.\_Empty problem.  
But normally the default policy would allow you to run the eval with random behavior, as a baseline number.  
Maybe the code can be structured a bit better for Eval?
