gipc
gipc copied to clipboard
Sockets kept open by child process
Originally reported by: eurleif (Bitbucket: eurleif, GitHub: Unknown)
Here's a toy example which accepts TCP connections on port 12345. For each connection, it spawns a child process, which sleeps for 5 seconds before exiting. It does not pass the socket into the child process. In the parent process, it sends a message to the client, and closes the socket.
My expected behavior when connecting to this server is for it to send me the message, then immediately close the connection. In reality, it sends me the message, then waits 5 seconds before closing the connection. It seems as though the socket is being kept open by the child process, even though the socket was not passed to it.
I've tested this with Python 2.7 and 3.5, with gevent 1.1.2 and gipc 0.6.0, on Ubuntu 16.04.
Is this intended behavior? I certainly find it unexpected, since the docs mention closing handles.
#!python
from gevent import sleep, spawn
from gevent.server import StreamServer
import gipc
def child():
sleep(5)
def handle(socket, address):
gipc.start_process(target=child)
socket.sendall(b'Spawned a child process. Good bye!\r\n')
socket.close()
if __name__ == '__main__':
server = StreamServer(('127.0.0.1', 12345), handle)
server.serve_forever()
- Bitbucket: https://bitbucket.org/jgehrcke/gipc/issue/22