Skip to content

Commit ac26b02

Browse files
Bug fix for when geven monkey patches are applied.
1 parent 950d9b0 commit ac26b02

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Diff for: examples/gevent-get-input.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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)

Diff for: prompt_toolkit/eventloop/inputhook.py

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"""
2525
from __future__ import unicode_literals
2626
import os
27+
import select
2728
import 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.

0 commit comments

Comments
 (0)