Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribute a new gevent-compliant event loop (see issue #112) #130

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mguijarr
Copy link

The gevent-compliant event loop is activated by passing gevent=True
to the embed method of repl module.
The event loop code is heavily inspired from the prompt-toolkit POSIX
event loop, adapted to gevent. More details in file contrib/gevent_eventloop.py

…t#112)

The gevent-compliant event loop is activated by passing `gevent=True`
to the `embed` method of `repl` module.
The event loop code is heavily inspired from the prompt-toolkit POSIX
event loop, adapted to gevent. More details in file `contrib/gevent_eventloop.py`
@jonathanslenders
Copy link
Member

Thanks for this pull request, I really appreciate it.

I'm not merging it however. After I discovered some issues, I took some time to debug the issue and found that it can be solved like in this change in prompt-toolkit: prompt-toolkit/python-prompt-toolkit@ac26b02

Does that work for you?

@mguijarr
Copy link
Author

mguijarr commented Jul 14, 2016

@jonathanslenders thanks a lot for having considered my PR and to take a look at the problem with gevent.

Your proposal does fix the issue with monkey.patch_all(), however it doesn't help with the other issue I found (see comments in #112) when threads are not monkey patched, ie. not replaced by gevent greenlets.

It is a common idiom I think to not patch threads, for example if someone wants to do some heavy computation in threads but still wants to use gevent for non-blocking I/O.

So, even with the new code the following consumes all file descriptors (look at lsof -a -p PID | wc -l output each time you hit Enter key):

from gevent import monkey; monkey.patch_all(thread=False)

from prompt_toolkit.shortcuts import prompt, create_eventloop

def dummy_inputhook(*a):
    pass

while True:
  eventloop = create_eventloop(inputhook=dummy_inputhook)
  # Ask for input.
  answer = prompt(u'Give me some input: ', eventloop=eventloop)
  print('You said: %s' % answer)

(in reality I did my tests with ptpython in REPL, I guess the code above with the while does the same to reproduce the problem I saw)

@JohnLunzer
Copy link

@jonathanslenders, was a decision made on which route to take on this? It's not clear, was issue #112 solved via the prompt-toolkit commit you mentioned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants