mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-08 14:41:55 +00:00
preliminary support for detachable pyshell
This commit is contained in:
@@ -50,7 +50,7 @@ struct option uwsgi_python_options[] = {
|
||||
#ifndef UWSGI_PYPY
|
||||
{"no-site", no_argument, &Py_NoSiteFlag, 1},
|
||||
#endif
|
||||
{"pyshell", no_argument, 0, LONG_ARGS_PYSHELL},
|
||||
{"pyshell", optional_argument, 0, LONG_ARGS_PYSHELL},
|
||||
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
@@ -731,7 +731,9 @@ int uwsgi_python_manage_options(int i, char *optarg) {
|
||||
case LONG_ARGS_PYSHELL:
|
||||
uwsgi.honour_stdin = 1;
|
||||
up.pyshell = 1;
|
||||
uwsgi.to_hell = 1;
|
||||
if (optarg) {
|
||||
up.pyshell_pts = optarg;
|
||||
}
|
||||
return 1;
|
||||
case LONG_ARGS_PYIMPORT:
|
||||
uwsgi_string_new_list(&up.import_list, optarg);
|
||||
@@ -1364,6 +1366,11 @@ void uwsgi_python_fixup() {
|
||||
uwsgi.p[30]->init_thread = NULL;
|
||||
}
|
||||
|
||||
int posix_openpt(int);
|
||||
int grantpt(int);
|
||||
int unlockpt(int);
|
||||
char *ptsname(int);
|
||||
|
||||
void uwsgi_python_hijack(void) {
|
||||
// the pyshell will be execute only in the first worker
|
||||
|
||||
@@ -1371,6 +1378,20 @@ void uwsgi_python_hijack(void) {
|
||||
if (up.pyshell && uwsgi.mywid == 1) {
|
||||
UWSGI_GET_GIL;
|
||||
PyImport_ImportModule("readline");
|
||||
if (up.pyshell_pts) {
|
||||
|
||||
int masterfd = posix_openpt(O_RDWR|O_NOCTTY);
|
||||
grantpt (masterfd);
|
||||
unlockpt (masterfd);
|
||||
uwsgi_log("slave = %s\n", ptsname (masterfd));
|
||||
dup2(masterfd, 0);
|
||||
dup2(masterfd, 1);
|
||||
dup2(masterfd, 2);
|
||||
for(;;) {
|
||||
PyRun_InteractiveLoop(stdin, "uwsgi");
|
||||
uwsgi_log("again !!!\n");
|
||||
}
|
||||
}
|
||||
PyRun_InteractiveLoop(stdin, "uwsgi");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -834,7 +834,7 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) {
|
||||
|
||||
PyObject *what;
|
||||
char *filename;
|
||||
size_t chunk;
|
||||
size_t chunk = 0;
|
||||
off_t pos = 0;
|
||||
size_t filesize = 0;
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
@@ -890,7 +890,20 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) {
|
||||
wsgi_req->sendfile_fd_pos = pos;
|
||||
|
||||
// do sendfile
|
||||
wsgi_req->response_size += uwsgi_sendfile(wsgi_req);
|
||||
if (uwsgi.async > 1) {
|
||||
ssize_t sf_len = uwsgi_sendfile(wsgi_req);
|
||||
if (sf_len > 0) {
|
||||
wsgi_req->response_size += sf_len;
|
||||
while(wsgi_req->sendfile_fd_pos < wsgi_req->sendfile_fd_size) {
|
||||
sf_len = uwsgi_sendfile(wsgi_req);
|
||||
if (sf_len <= 0) break;
|
||||
wsgi_req->response_size += sf_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
wsgi_req->response_size += uwsgi_sendfile(wsgi_req);
|
||||
}
|
||||
|
||||
// revert to old values
|
||||
wsgi_req->sendfile_fd = tmp_fd;
|
||||
|
||||
@@ -128,6 +128,7 @@ struct uwsgi_python {
|
||||
char *test_module;
|
||||
|
||||
int pyshell;
|
||||
char *pyshell_pts;
|
||||
|
||||
struct uwsgi_string_list *python_path;
|
||||
struct uwsgi_string_list *import_list;
|
||||
|
||||
Reference in New Issue
Block a user