[issue29926] time.sleep ignores _thread.interrupt_main()

2017-06-28 Thread Louie Lu
Louie Lu added the comment: Based on Martin's patch, I slightly changed the logic for the patch. So, I add a `finish` flag to detect the code in Executive.runcode is done or not. `interrupt_the_server` will first SIGINT via interrupt_main, if this doesn't work after 0.2 seconds, it will then s

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-06-28 Thread Louie Lu
Changes by Louie Lu : -- pull_requests: +2520 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pyth

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-06-27 Thread Louie Lu
Louie Lu added the comment: Other operation which will block the process will do the same as time.sleep(), too. >>> import socket >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >>> s.bind(('', 25000)) >>> s.recv(100) IDLE will ignore this control-c, too. ---

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-04-02 Thread Terry J. Reedy
Terry J. Reedy added the comment: A fix for 3.6+ will be better than nothing ;-) -- ___ Python tracker ___ ___ Python-bugs-list mailin

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-04-02 Thread Martin Panter
Martin Panter added the comment: BTW pthread_kill was only added to Python 3.3, so is not available for Python 2. I’m not sure what the best fix for 2.7 would be. Maybe it’s not worth it, or maybe you can find another way to a signal to the user process or its main thread without interfering w

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-04-02 Thread Martin Panter
Martin Panter added the comment: Hi Terry, this patch is what I imagined a fix would look like for Linux. I am not familiar with Idle (internally nor externally), so there may be improvements you can make. It works as I expected for normal blocking functions and a tight “for” loop: it interru

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-03-28 Thread Eryk Sun
Eryk Sun added the comment: > Even is IDLE is started from a console, the user execution process > is not attached to one. Actually, the execution process is attached to a console, but it doesn't use it for sys.std*. Try open('con', 'w').write('spam\n') > It is much like closing a termin

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-03-28 Thread Terry J. Reedy
Terry J. Reedy added the comment: Even is IDLE is started from a console, the user execution process is not attached to one. What I want, from an IDLE perspective, is for ^C in IDLE's shell to work as well as it does in a terminal. That means either fixing _thread.interrupt_main to always do

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-03-28 Thread Eryk Sun
Eryk Sun added the comment: Nathaniel's suggestion to update the implementation to work with raise(SIGINT) sounds like a good idea. Fpr Windows, GenerateConsoleCtrlEvent is definitely a non-starter. PyErr_SetInterrupt shouldn't depend on having an attached console. IDLE generally runs without

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-03-28 Thread Nathaniel Smith
Nathaniel Smith added the comment: (oh, in case it wasn't obvious: the advantage of raise() over kill() and pthread_kill() is that raise() works everywhere, including Windows, so it would avoid platform specific logic. Or if you don't like raise() for some reason then you can get the same effe

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-03-28 Thread Nathaniel Smith
Nathaniel Smith added the comment: If you want to trigger the standard signal handling logic, then raise(SIGINT) is also an option. On unix it probably won't help because of issue 21895, but using raise() here + fixing 21895 by using pthread_kill in the c level signal handler would together gi

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-03-28 Thread Eryk Sun
Eryk Sun added the comment: For Windows the event should be set after trip_signal(SIGINT). That way the flag is guaranteed to be tripped when PyErr_CheckSignals is called from the time module's pysleep() function. This in turn calls the default SIGINT handler that raises a KeyboardInterrupt.

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-03-28 Thread Terry J. Reedy
Terry J. Reedy added the comment: Eryk, would the addition go before or after "trip_signal(SIGINT);" I posted "Issue with _thread.interrupt_main (29926)" on pydev list. Steven D'Aprano verified delayed response on *nix. Martin Panter said "Looking at the implementation, _thread.interrupt_main

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-03-27 Thread Eryk Sun
Eryk Sun added the comment: It's simple to fix this in Python 3 on Windows. PyErr_SetInterrupt in Modules/signalmodule.c needs the following addition: #ifdef MS_WINDOWS SetEvent(sigint_event); #endif In the main thread on Windows, time.sleep() waits on this event. On Unix, ti

[issue29926] time.sleep ignores _thread.interrupt_main()

2017-03-27 Thread Terry J. Reedy
Terry J. Reedy added the comment: Scratch my confusion. I added "print('after')" immediately after _thread.interrupt_main() in idlelib.run.Executor.interrupt_the_server() and 'after' is printed in Shell right after I hit ^C but a time.sleep(10) is not immediately interrupted and 'KeyboardInte