Skip to content

Monitor does not exit on KeyboardInterrupt #572

@jfolz

Description

@jfolz

Python 2.7:
4.23.4 2.7.6 (default, Nov 23 2017, 15:49:48)
[GCC 4.8.4] linux2

Python 3.6:
4.23.4 3.6.3 (default, Dec 4 2017, 11:26:35)
[GCC 4.8.4] linux

In Python 2.7 everything works as expected: interpreter exits when KeyboardInterrupt is received.
In Python 3.6 the monitor thread does not exit if KeyboardInterrupt is received before TMonitor.sleep_interval has passed once.

In both cases TMonitor.was_killed is never set, but in Python 3.6 the monitor requires a second KeyboardInterrupt to exit.

from __future__ import print_function, division, unicode_literals
import time
import random
import tqdm
p = tqdm.tqdm(range(1000))
try:
    for i in p:
        time.sleep(random.random() / 10)
finally:
    print('was_killed:', tqdm.tqdm.monitor.was_killed.is_set())
    # tqdm.tqdm.monitor.was_killed.set()

Uncomment the last line to "fix" the problem in 3.6.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions