summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Caron <andre.l.caron@gmail.com>2016-09-03 14:43:27 -0400
committerAndre Caron <andre.l.caron@gmail.com>2016-09-05 19:07:26 -0400
commit7fb15c6689e4be853948bc71803cd3a33f3211bd (patch)
tree3b8fcc6ef770348088669ac7be4dd7f572e6dce8
parent1b9a35c3a13dc1c74174e9f449e4388435485b2a (diff)
downloadpsutil-7fb15c6689e4be853948bc71803cd3a33f3211bd.tar.gz
Releases GIL while fetching TCP and UDP tables on Windows.
-rw-r--r--psutil/_psutil_windows.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index a2778e05..31f9d86a 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -1482,9 +1482,13 @@ static DWORD __GetExtendedTcpTable(_GetExtendedTcpTable call,
// that the size of the table increases between the moment where we
// query the size and the moment where we query the data. Therefore, it's
// important to call this in a loop to retry if that happens.
+ //
+ // Also, since we may loop a theoretically unbounded number of times here,
+ // release the GIL while we're doing this.
DWORD error = ERROR_INSUFFICIENT_BUFFER;
*size = 0;
*data = NULL;
+ Py_BEGIN_ALLOW_THREADS;
error = call(NULL, size, FALSE, address_family,
TCP_TABLE_OWNER_PID_ALL, 0);
while (error == ERROR_INSUFFICIENT_BUFFER)
@@ -1501,6 +1505,7 @@ static DWORD __GetExtendedTcpTable(_GetExtendedTcpTable call,
*data = NULL;
}
}
+ Py_END_ALLOW_THREADS;
return error;
}
@@ -1518,9 +1523,13 @@ static DWORD __GetExtendedUdpTable(_GetExtendedUdpTable call,
// that the size of the table increases between the moment where we
// query the size and the moment where we query the data. Therefore, it's
// important to call this in a loop to retry if that happens.
+ //
+ // Also, since we may loop a theoretically unbounded number of times here,
+ // release the GIL while we're doing this.
DWORD error = ERROR_INSUFFICIENT_BUFFER;
*size = 0;
*data = NULL;
+ Py_BEGIN_ALLOW_THREADS;
error = call(NULL, size, FALSE, address_family,
UDP_TABLE_OWNER_PID, 0);
while (error == ERROR_INSUFFICIENT_BUFFER)
@@ -1537,6 +1546,7 @@ static DWORD __GetExtendedUdpTable(_GetExtendedUdpTable call,
*data = NULL;
}
}
+ Py_END_ALLOW_THREADS;
return error;
}