Thread
and Greenlet
have different behavior in an interactive environment. In some cases, the main event loop needs to be cracked.
Greenlet
is a gevent
module that is a parallel task in python. It has an internal context switch other than Python (pthread), and concurrency works very well (in my experience). Some of the problems with Greenlets are that they block the blocking of C-system calls and socket interactions if they are not patched by monkeys (module in gevent
).
The main loop of the loop must be fixed so that the green panels work correctly ... If you create a green shell in an interactive environment, it will not switch contexts and will not execute, I forgot, from my point of view, how to fix the main loop of the event (it will be added later).
Failure example:
In [1]: from gevent.greenlet import Greenlet In [2]: def print_hi(): ...: print 'hi' ...: In [3]: print_hi() hi In [4]: g = Greenlet(print_hi) In [5]: g.start()
Edit:
After looking at some code for this project here, we cracked the ipython input hook to use gevent
import sys import select import gevent def stdin_ready(): infds, outfds, erfds = select.select([sys.stdin], [], [], 0) if infds: return True else: return False def inputhook_gevent(): try: while not stdin_ready(): gevent.sleep(0.001) except KeyboardInterrupt: pass return 0
Corrected example:
In [6]: def say_hi(): ...: print "hi" ...: In [7]: g = gevent.greenlet.Greenlet(say_hi) In [8]: g.start() In [9]: hi <-- Cursor is here so it printed hi
source share