Pan
2017-09-27 13:36:53 UTC
Hello,
First off, thank you for the awesome library.
I have a question regarding use of gevent via a C-API, specifically in
Cython generated code. Have seen the pxd definitions for cares and libev in
the project but it does not look like the gevent API itself is exposed via
Cython.
The use case I have for this is with gevent being used as an IO library for
a C library (libssh2), that is in turn used via a python wrapper extension (
ssh2-python <https://github.com/ParallelSSH/ssh2-python>). The C library
natively supports non-blocking mode and gevent is used in python space to
connect the python C library wrapper with an event loop and co-operative
sockets. So far so good, see gevent using client here
<https://github.com/ParallelSSH/parallel-ssh/blob/libssh2/pssh/ssh2_client.py>
.
Since the underlying library is in C, the library also uses native threads
via gevent's native thread pool to offload non network related blocking
calls to threads. However, when it comes to waiting for network I/O, those
threads have to acquire the GIL in order to call gevent's co-operative
select.
For example reading from network and writing to local file - the file write
is implemented in C, releases the GIL and runs in a native thread while
reading from network has to call gevent.select and therefore has to hold
the GIL
<https://github.com/ParallelSSH/parallel-ssh/blob/libssh2/pssh/native/ssh2.pyx#L125-L131>.
This, however, blocks other threads from running.
This is what I would like to avoid by interfacing with a C-API. If gevent's
select calls were done in C space, without the GIL, the rest of the
application could continue processing. The library is a parallel SSH client
so this is quite common.
Is this at all possible? If not, would running separate hubs in multiple
native threads achieve the same result, ie not blocking other native
threads from running due to holding the GIL? Or would those hubs also need
the GIL, effectively serialising them?
Am aware of gipc but as the library being used is native code, multiple
processes with IPC is not a good fit for this use case.
Another use case I have in mind is for scaling gevent past a single core
with multiple hubs in native threads that do not hold the GIL. This is
feasible in this case as a native library is used so the GIL will not
serialise everything (this is what gipc aims to solve).
Thank you for reading.
Pan
First off, thank you for the awesome library.
I have a question regarding use of gevent via a C-API, specifically in
Cython generated code. Have seen the pxd definitions for cares and libev in
the project but it does not look like the gevent API itself is exposed via
Cython.
The use case I have for this is with gevent being used as an IO library for
a C library (libssh2), that is in turn used via a python wrapper extension (
ssh2-python <https://github.com/ParallelSSH/ssh2-python>). The C library
natively supports non-blocking mode and gevent is used in python space to
connect the python C library wrapper with an event loop and co-operative
sockets. So far so good, see gevent using client here
<https://github.com/ParallelSSH/parallel-ssh/blob/libssh2/pssh/ssh2_client.py>
.
Since the underlying library is in C, the library also uses native threads
via gevent's native thread pool to offload non network related blocking
calls to threads. However, when it comes to waiting for network I/O, those
threads have to acquire the GIL in order to call gevent's co-operative
select.
For example reading from network and writing to local file - the file write
is implemented in C, releases the GIL and runs in a native thread while
reading from network has to call gevent.select and therefore has to hold
the GIL
<https://github.com/ParallelSSH/parallel-ssh/blob/libssh2/pssh/native/ssh2.pyx#L125-L131>.
This, however, blocks other threads from running.
This is what I would like to avoid by interfacing with a C-API. If gevent's
select calls were done in C space, without the GIL, the rest of the
application could continue processing. The library is a parallel SSH client
so this is quite common.
Is this at all possible? If not, would running separate hubs in multiple
native threads achieve the same result, ie not blocking other native
threads from running due to holding the GIL? Or would those hubs also need
the GIL, effectively serialising them?
Am aware of gipc but as the library being used is native code, multiple
processes with IPC is not a good fit for this use case.
Another use case I have in mind is for scaling gevent past a single core
with multiple hubs in native threads that do not hold the GIL. This is
feasible in this case as a native library is used so the GIL will not
serialise everything (this is what gipc aims to solve).
Thank you for reading.
Pan
--
You received this message because you are subscribed to the Google Groups "gevent: coroutine-based Python network library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gevent+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "gevent: coroutine-based Python network library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gevent+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.