diff --git a/src/python.c b/src/python.c index d40564d..a825673 100644 --- a/src/python.c +++ b/src/python.c @@ -1657,7 +1657,7 @@ pysocket_alloc(void) static void pysocket_dealloc(struct pysocket *sock) { - if (sock->scheduled) { + if (sock->scheduled && sock->fd == -1) { kore_platform_disable_read(sock->fd); #if !defined(__linux__) kore_platform_disable_write(sock->fd); @@ -1838,6 +1838,14 @@ pysocket_connect(struct pysocket *sock, PyObject *args) static PyObject * pysocket_close(struct pysocket *sock, PyObject *args) { + if (sock->scheduled) { + sock->scheduled = 0; + kore_platform_disable_read(sock->fd); +#if !defined(__linux__) + kore_platform_disable_write(sock->fd); +#endif + } + if (sock->socket != NULL) { Py_DECREF(sock->socket); sock->socket = NULL;