Skip to content

Commit

Permalink
Merge pull request #1713 from maedoc/gh-1712-local-var-ref
Browse files Browse the repository at this point in the history
avoid unbound local ref on exc before first sample
  • Loading branch information
ColCarroll committed Jan 26, 2017
2 parents 834e87f + 7f94258 commit 59f6c85
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pymc3/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,15 @@ def _sample(draws, step=None, start=None, trace=None, chain=0, tune=None,
if progressbar:
sampling = tqdm(sampling, total=draws)
try:
strace = None
for strace in sampling:
pass
except KeyboardInterrupt:
strace.close()
return MultiTrace([strace]) # pylint: disable=undefined-loop-variable
result = [] if strace is None else [strace]
except KeyboardInterrupt as exc:
if strace is not None:
strace.close()
raise exc
return MultiTrace(result)


def iter_sample(draws, step, start=None, trace=None, chain=0, tune=None,
Expand Down

0 comments on commit 59f6c85

Please sign in to comment.