Skip to content

Commit

Permalink
fix: learn/predict exceptions were causing a destructor to throw (#3659)
Browse files Browse the repository at this point in the history
* fix: learn/predict exceptions were causing a destructor to throw

* Update learner.cc

* trigger CI

* fix onethread
  • Loading branch information
jackgerrits committed Jan 28, 2022
1 parent bdcec67 commit 01bdf2c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions vowpalwabbit/learner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class single_example_handler
_context.template process<example, learn_ex>(*ec);
}

void process_remaining() {}

private:
context_type _context;
};
Expand Down Expand Up @@ -162,11 +164,7 @@ class multi_example_handler

public:
multi_example_handler(const context_type context) : _context(context) {}

~multi_example_handler()
{
if (!ec_seq.empty()) { _context.template process<multi_ex, learn_multi_ex>(ec_seq); }
}
~multi_example_handler() = default;

void on_example(example* ec)
{
Expand All @@ -192,6 +190,15 @@ class multi_example_handler
}
}

void process_remaining()
{
if (!ec_seq.empty())
{
_context.template process<multi_ex, learn_multi_ex>(ec_seq);
ec_seq.clear();
}
}

private:
context_type _context;
multi_ex ec_seq;
Expand Down Expand Up @@ -235,8 +242,7 @@ template <typename queue_type, typename handler_type>
void process_examples(queue_type& examples, handler_type& handler)
{
example* ec;

while ((ec = examples.pop()) != nullptr) handler.on_example(ec);
while ((ec = examples.pop()) != nullptr) { handler.on_example(ec); }
}

template <typename context_type>
Expand All @@ -247,12 +253,14 @@ void generic_driver(ready_examples_queue& examples, context_type& context)
using handler_type = multi_example_handler<context_type>;
handler_type handler(context);
process_examples(examples, handler);
handler.process_remaining();
}
else
{
using handler_type = single_example_handler<context_type>;
handler_type handler(context);
process_examples(examples, handler);
handler.process_remaining();
}
drain_examples(context.get_master());
}
Expand Down Expand Up @@ -282,6 +290,7 @@ void generic_driver_onethread(VW::workspace& all)
process_examples(examples_queue, handler);
};
parse_dispatch(all, multi_ex_fptr);
handler.process_remaining();
all.l->end_examples();
}

Expand Down

0 comments on commit 01bdf2c

Please sign in to comment.