File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ """
3+ For testing: test to make sure that everything still works when gevent monkey
4+ patches are applied.
5+ """
6+ from __future__ import unicode_literals
7+ from gevent .monkey import patch_all
8+ from prompt_toolkit .shortcuts import prompt , create_eventloop
9+
10+
11+ if __name__ == '__main__' :
12+ # Apply patches.
13+ patch_all ()
14+
15+ # There were some issues in the past when the event loop had an input hook.
16+ def dummy_inputhook (* a ):
17+ pass
18+ eventloop = create_eventloop (inputhook = dummy_inputhook )
19+
20+ # Ask for input.
21+ answer = prompt ('Give me some input: ' , eventloop = eventloop )
22+ print ('You said: %s' % answer )
Original file line number Diff line number Diff line change 2424"""
2525from __future__ import unicode_literals
2626import os
27+ import select
2728import threading
2829
2930__all__ = (
@@ -73,6 +74,14 @@ def thread():
7374
7475 # Flush the read end of the pipe.
7576 try :
77+ # Before calling 'os.read', call select.select. This fixes a bug
78+ # with Gevent where the following read call blocked the select call
79+ # from the eventloop that we call through 'input_is_ready_func' in
80+ # the above thread.
81+ # This appears to be only required when gevent.monkey.patch_all()
82+ # has been executed. Otherwise it doesn't do much.
83+ select .select ([self ._r ], [], [])
84+
7685 os .read (self ._r , 1024 )
7786 except OSError :
7887 # This happens when the window resizes and a SIGWINCH was received.
You can’t perform that action at this time.
0 commit comments