Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeongyun0916 committed Feb 21, 2023
1 parent 3e45ffc commit aaa35d3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
17 changes: 9 additions & 8 deletions Lib/test/memory_watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
except (ValueError, AttributeError):
page_size = 4096

while True:
sys.stdin.seek(0)
statm = sys.stdin.read()
data = int(statm.split()[5])
sys.stdout.write(" ... process data size: {data:.1f}G\n"
.format(data=data * page_size / (1024 ** 3)))
sys.stdout.flush()
time.sleep(1)
if __name__ == "__main__":
while True:
sys.stdin.seek(0)
statm = sys.stdin.read()
data = int(statm.split()[5])
sys.stdout.write(" ... process data size: {data:.1f}G\n"
.format(data=data * page_size / (1024 ** 3)))
sys.stdout.flush()
time.sleep(1)
7 changes: 5 additions & 2 deletions Lib/test/test_fcntl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from test.support import verbose, cpython_only
from test.support.import_helper import import_module
from test.support.os_helper import TESTFN, unlink

from test.memory_watchdog import page_size

# Skip test if no fcntl module.
fcntl = import_module('fcntl')
Expand Down Expand Up @@ -196,10 +196,13 @@ def test_fcntl_f_getpath(self):
hasattr(fcntl, "F_SETPIPE_SZ") and hasattr(fcntl, "F_GETPIPE_SZ"),
"F_SETPIPE_SZ and F_GETPIPE_SZ are not available on all platforms.")
def test_fcntl_f_pipesize(self):
print(max(page_size, fcntl.F_GETPIPE_SZ)) // 4096, 1032
test_pipe_r, test_pipe_w = os.pipe()
try:
# Get the default pipesize with F_GETPIPE_SZ
pipesize_default = fcntl.fcntl(test_pipe_w, fcntl.F_GETPIPE_SZ)
print('start mhg')
pipesize_default = fcntl.fcntl(test_pipe_w, 1032)
print('end mhg')
pipesize = pipesize_default // 2 # A new value to detect change.
if pipesize < 512: # the POSIX minimum
raise unittest.SkipTest(
Expand Down
12 changes: 12 additions & 0 deletions Modules/fcntlmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,48 +58,60 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
int async_err = 0;

if (PySys_Audit("fcntl.fcntl", "iiO", fd, code, arg ? arg : Py_None) < 0) {
printf("mhg1\n");
return NULL;
}

if (arg != NULL) {
int parse_result;

if (PyArg_Parse(arg, "s#", &str, &len)) {
printf("mhg2\n");
if ((size_t)len > sizeof buf) {
printf("mhg3\n");
PyErr_SetString(PyExc_ValueError,
"fcntl string arg too long");
return NULL;
}
memcpy(buf, str, len);
do {
printf("mhg4\n");
Py_BEGIN_ALLOW_THREADS
ret = fcntl(fd, code, buf);
Py_END_ALLOW_THREADS
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
if (ret < 0) {
printf("mhg5\n");
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL;
}
printf("mhg6\n");
return PyBytes_FromStringAndSize(buf, len);
}

printf("mhg7\n");
PyErr_Clear();
parse_result = PyArg_Parse(arg,
"I;fcntl requires a file or file descriptor,"
" an integer and optionally a third integer or a string",
&int_arg);
if (!parse_result) {
printf("mhg8\n");
return NULL;
}
printf("mhg9\n");
}

do {
Py_BEGIN_ALLOW_THREADS
ret = fcntl(fd, code, (int)int_arg);
Py_END_ALLOW_THREADS
printf("mhg10 ret: %d, errno: %d, async_err: %d, args: %d %d %d\n", ret, errno, async_err, fd, code, (int)int_arg);
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
if (ret < 0) {
printf("mhg11\n");
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL;
}
printf("mhg12\n");
return PyLong_FromLong((long)ret);
}

Expand Down

0 comments on commit aaa35d3

Please sign in to comment.