New submission from Bogdan Popa <popa.bogd...@gmail.com>: I ran into this while backporting some code from 3.6 to 3.5 and 3.4. The following piece of code prints one line every second, as expected, on 3.6 and 3.5, but it doesn't on 3.4. It looks like the signal is able to wake up the main thread from sleeping:
``` import time import signal def handle(signum, mask): print("received signal at", time.time()) signal.setitimer(signal.ITIMER_REAL, 1, 1) signal.signal(signal.SIGALRM, handle) for _ in range(2): now = time.time() delta = 1 - (time.time() - int(time.time())) time.sleep(delta) print(now, delta, time.time()) ``` If I remove the timer, then everything works as expected on 3.4. Here is some sample output from 3.6: ``` 1510913832.4726589 0.5273411273956299 1510913833.000339 received signal at 1510913833.477888 1510913833.000449 0.9995510578155518 1510913834.000187 ``` And some from 3.4: ``` 1510913813.525479 0.4745209217071533 1510913814.004106 received signal at 1510913814.529313 1510913814.004233 0.9957659244537354 1510913814.529413 ``` ---------- components: Interpreter Core messages: 306427 nosy: Bogdan Popa priority: normal severity: normal status: open title: time.sleep(n) interrupted by signal versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32057> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com