Fix for write_stats error when using threads pool.  Closes #1631