Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pyworker.c 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * Copyright (C) 2019 Weber Yann
  3. *
  4. * This file is part of PyFCGI.
  5. *
  6. * PyFCGI is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * PyFCGI is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "pyworker.h"
  20. static short _wtimeout;
  21. /**@brief 1 if worker idle else 0 */
  22. static short _worker_idle;
  23. /**@brief Indicate that a worker is idle */
  24. static inline void worker_set_idle();
  25. /**@brief Indicate that a worker is busy */
  26. static inline void worker_set_busy();
  27. /**@brief Process results from a pep333 worker
  28. * @param FCGX_Stream* out stream from libFCGI
  29. * @param PyObject* application function returned value
  30. */
  31. static inline int work333_send_result(FCGX_Stream*, PyObject* ret);
  32. static int worker_piper_sigrcv = 0;
  33. int work333(int wrk_id)
  34. {
  35. PyObject *entry_fun, *pyflush[2], *py_osmod, *entry_ret, *environ,
  36. *start_response, *args;
  37. FCGX_Stream *in_stream, *out_stream, *err_stream;
  38. char **envp;
  39. int count, pipe_out[2], pipe_err[2];
  40. int max_reqs;
  41. struct timeval start, stop;
  42. max_reqs = PyFCGI_conf.max_reqs;
  43. pyfcgi_log(LOG_INFO, "Worker started with PEP333 App");
  44. pyinit();
  45. pyfcgi_log(LOG_DEBUG, "Python started");
  46. update_python_fd(pipe_out, pipe_err);
  47. fetch_pyflush(&(pyflush[0]), &(pyflush[1]));
  48. //importing os
  49. py_osmod = python_osmod();
  50. // loading module
  51. entry_fun = import_entrypoint();
  52. pyfcgi_log(LOG_INFO, "Waiting request with %s.%s()",
  53. PyFCGI_conf.py_entrymod, PyFCGI_conf.py_entryfun);
  54. if(!entry_fun) //but exit if import failed
  55. {
  56. pyfcgi_log(LOG_ALERT, "Unable to import entrypoint");
  57. exit(PYFCGI_FATAL);
  58. }
  59. start_response = get_start_response();
  60. _worker_idle = 0;
  61. worker_set_idle();
  62. // requests accepting loop
  63. count = 0;
  64. while ((!count || count != max_reqs) &&
  65. FCGX_Accept(&in_stream, &out_stream, &err_stream, &envp) >= 0)
  66. {
  67. pyfcgi_wd_arm();
  68. gettimeofday(&start, NULL);
  69. worker_set_busy();
  70. count++;
  71. environ = update_pyenv(py_osmod, envp);
  72. _wtimeout = 0;
  73. libpyfcgi_clean_response();
  74. libpyfcgi.out = out_stream;
  75. libpyfcgi.in = in_stream;
  76. args = Py_BuildValue("OO", environ, start_response);
  77. // Call application function
  78. entry_ret = PyObject_CallObject(entry_fun, args);
  79. if(entry_ret && entry_ret != Py_None )
  80. {
  81. Py_INCREF(entry_ret);
  82. }
  83. if(_wtimeout)
  84. {
  85. PyObject *type, *exc, *tb, *tmp;
  86. // Changing exception to a TimeoutError, but keeping
  87. // the traceback to display
  88. PyErr_Fetch(&type, &exc, &tb);
  89. PyErr_SetString(PyExc_TimeoutError, "Request timeout");
  90. PyErr_Fetch(&type, &exc, &tmp);
  91. PyErr_Restore(type, exc, tb);
  92. log_expt(LOG_ERR);
  93. libpyfcgi_timeout(); // Sending headers if possible
  94. }
  95. if(PyErr_Occurred())
  96. {
  97. pyfcgi_log(LOG_ERR, "PEP333 entrypoint function triggered an exception");
  98. log_expt(LOG_ERR);
  99. }
  100. // able to process returned value
  101. // Simulate python call of libpyfcgi.write_body()
  102. if(entry_ret && entry_ret != Py_None)
  103. {
  104. _pyfcgi_write_body(entry_ret);
  105. if(PyErr_Occurred())
  106. {
  107. log_expt(LOG_ERR);
  108. }
  109. Py_DECREF(entry_ret);
  110. }
  111. // clean stuffs
  112. Py_DECREF(args);
  113. Py_DECREF(environ);
  114. // flush & logs pystdout & pystderr
  115. worker_log_pipes(pipe_out[0], pipe_err[0], pyflush);
  116. FCGX_FClose(out_stream);
  117. FCGX_FClose(in_stream);
  118. FCGX_FClose(err_stream);
  119. FCGI_Finish();
  120. gettimeofday(&stop, NULL);
  121. stop.tv_sec = stop.tv_sec - start.tv_sec;
  122. stop.tv_usec = stop.tv_usec - start.tv_usec;
  123. if(stop.tv_usec < 0)
  124. {
  125. stop.tv_usec += 1000000;
  126. stop.tv_sec -= 1;
  127. }
  128. pyfcgi_wd_pause();
  129. if(_wtimeout)
  130. {
  131. exit(PYFCGI_TIMEOUT);
  132. }
  133. pyfcgi_log(LOG_DEBUG, "Worker[%d] request %d END [OK] %lu bytes in %ld.%06lds",
  134. wrk_id, count, libpyfcgi.rep_sz, stop.tv_sec, stop.tv_usec);
  135. worker_set_idle();
  136. }
  137. worker_set_busy();
  138. return 0;
  139. }
  140. static inline int work333_send_result(FCGX_Stream *out, PyObject* ret)
  141. {
  142. return 0;
  143. }
  144. int work(int wrk_id)
  145. {
  146. PyObject *entry_fun, *pystdout_flush, *pystderr_flush, *py_osmod,
  147. *environ;
  148. FCGX_Stream *in_stream, *out_stream, *err_stream;
  149. char **envp;
  150. int count, pipe_out[2], pipe_err[2], pipe_ctl[2], err, piper_status;
  151. int max_reqs;
  152. struct sigaction act;
  153. struct timeval start, stop;
  154. sigset_t emptyset;
  155. char buf[PIPE_BUF];
  156. size_t rep_sz;
  157. piper_args_t piper_args;
  158. char *piper_stack;
  159. max_reqs = PyFCGI_conf.max_reqs;
  160. piper_args.wrk_id = wrk_id;
  161. piper_args.act = &act;
  162. // preparing sigaction for piper
  163. if(sigemptyset(&emptyset))
  164. {
  165. err = errno;
  166. pyfcgi_log( LOG_ALERT, "sigemptyset fails in piper : %s",
  167. strerror(err));
  168. exit(err);
  169. }
  170. act.sa_handler = worker_piper_sighandler;
  171. act.sa_mask = emptyset;
  172. //act.sa_flags = SA_RESTART;
  173. act.sa_flags = 0;
  174. act.sa_restorer = NULL;
  175. if( !(piper_stack = malloc(PIPER_STACK_SZ)) )
  176. {
  177. err = errno;
  178. pyfcgi_log(LOG_ALERT, "Error while allocating piper stack : %s",
  179. strerror(err));
  180. exit(err);
  181. }
  182. pyfcgi_log(LOG_INFO, "Worker %d started", wrk_id);
  183. update_python_path(); // add cwd to python path
  184. Py_Initialize(); // "start" python
  185. update_python_fd(pipe_out, pipe_err);
  186. piper_args.pystdout = pipe_out[0];
  187. piper_args.pystderr = pipe_err[0];
  188. fetch_pyflush(&pystdout_flush, &pystderr_flush);
  189. pyfcgi_log( LOG_INFO,
  190. "Worker[%d] Python started", wrk_id);
  191. //importing os
  192. py_osmod = python_osmod();
  193. // loading module
  194. entry_fun = import_entrypoint();
  195. pyfcgi_log( LOG_INFO,
  196. "Worker[%d] Waiting request with %s.%s()", wrk_id,
  197. PyFCGI_conf.py_entrymod, PyFCGI_conf.py_entryfun);
  198. if(!entry_fun) //but exit if import failed
  199. {
  200. pyfcgi_log(LOG_ALERT, "Unable to import entrypoint");
  201. exit(PYFCGI_FATAL);
  202. }
  203. if(pipe(pipe_ctl) == -1)
  204. {
  205. err = errno;
  206. pyfcgi_log(LOG_ALERT,
  207. "Worker[%d] Pipe fails for piper ctl : %s",
  208. wrk_id, strerror(err));
  209. exit(err);
  210. }
  211. piper_args.ctl_pipe = pipe_ctl[1];
  212. _worker_idle = 0;
  213. worker_set_idle();
  214. count = 0;
  215. while ((!count || count != max_reqs) && FCGX_Accept(&in_stream, &out_stream, &err_stream, &envp) >= 0)
  216. {
  217. pyfcgi_wd_arm();
  218. gettimeofday(&start, NULL);
  219. worker_set_busy();
  220. count++;
  221. piper_args.out = out_stream;
  222. //piper_args.req_id = count;
  223. worker_piper_sigrcv = 0;
  224. // if(!PyFCGI_conf.pep333)
  225. /**@todo avoid clone on each request... (using named pipes ?) */
  226. pid_t pid = clone(worker_piper, piper_stack + PIPER_STACK_SZ - 1,
  227. CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID | \
  228. SIGCHLD | \
  229. CLONE_FILES | CLONE_FS | CLONE_IO | CLONE_VM,
  230. &piper_args);
  231. if(pid < 0)
  232. {
  233. err = errno;
  234. pyfcgi_log(LOG_ALERT,
  235. "Worker[%d] req #%d Fork failed for piper : %s",
  236. wrk_id, count, strerror(err));
  237. exit(err);
  238. }
  239. environ = update_pyenv(py_osmod, envp);
  240. Py_DECREF(environ);
  241. //close(pipe_ctl[1]);
  242. PyObject_CallObject(entry_fun, NULL);
  243. if(PyErr_Occurred())
  244. {
  245. log_expt(LOG_ERR);
  246. }
  247. else
  248. {
  249. /*
  250. pyfcgi_log(LOG_DEBUG, "Worker[%d] request %d funcall [OK]",
  251. wrk_id, count);
  252. */
  253. }
  254. PyObject_CallObject(pystdout_flush, NULL);
  255. PyObject_CallObject(pystderr_flush, NULL);
  256. read(pipe_ctl[0], &buf, 1); // unblock when child ready
  257. FCGX_FClose(in_stream);
  258. FCGX_FClose(err_stream);
  259. //close(pipe_ctl[0]);
  260. kill(pid, WPIPER_SIG); //indicate child python call ended
  261. waitpid(pid, &piper_status, 0);
  262. if(WIFSIGNALED(piper_status))
  263. {
  264. pyfcgi_log(LOG_ERR,
  265. "Woker[%d] req #%d piper terminated by sig %d",
  266. wrk_id, count, WTERMSIG(piper_status));
  267. exit(40);
  268. }
  269. else if(WEXITSTATUS(piper_status))
  270. {
  271. pyfcgi_log(LOG_ERR,
  272. "Woker[%d] req #%d piper exited with error status %d",
  273. wrk_id, count, WEXITSTATUS(piper_status));
  274. exit(41);
  275. }
  276. FCGI_Finish();
  277. if(ctl_get_rep_sz(pipe_ctl[0], &rep_sz))
  278. {
  279. rep_sz = 0;
  280. }
  281. //Increase sem showing the worker is idle
  282. worker_set_idle();
  283. gettimeofday(&stop, NULL);
  284. stop.tv_sec = stop.tv_sec - start.tv_sec;
  285. stop.tv_usec = stop.tv_usec - start.tv_usec;
  286. if(stop.tv_usec < 0)
  287. {
  288. stop.tv_usec += 1000000;
  289. stop.tv_sec -= 1;
  290. }
  291. pyfcgi_wd_pause();
  292. pyfcgi_log(LOG_DEBUG, "Worker[%d] request %d END [OK] %lu bytes in %ld.%06lds",
  293. wrk_id, count, rep_sz, stop.tv_sec, stop.tv_usec);
  294. }
  295. worker_set_busy();
  296. free(piper_stack);
  297. Py_Exit(count == max_reqs ?0:EXIT_PYERR);
  298. }
  299. /*
  300. void worker_piper(int wrk_id, int req_id, int pystdout, int pystderr,
  301. int ctl_pipe, FCGX_Stream* out)
  302. */
  303. int worker_piper(void *ptr)
  304. {
  305. piper_args_t *args;
  306. struct pollfd fds[2];
  307. int err, ret, cont, poll_ret;
  308. short revents, closed, nfds;
  309. char buf[PIPE_BUF];
  310. size_t out_sz;
  311. args = ptr;
  312. int wrk_id, pystdout, pystderr, ctl_pipe;
  313. //int req_id;
  314. FCGX_Stream *out;
  315. struct sigaction *act;
  316. wrk_id = args->wrk_id;
  317. //req_id = args->req_id;
  318. pystdout = args->pystdout;
  319. pystderr = args->pystderr;
  320. ctl_pipe = args->ctl_pipe;
  321. out = args->out;
  322. act = args->act;
  323. if(sigaction(WPIPER_SIG, act, NULL))
  324. {
  325. err = errno;
  326. pyfcgi_log( LOG_ALERT, "Unable to sigaction in piper : %s",
  327. strerror(err));
  328. exit(err);
  329. }
  330. write(ctl_pipe, " ", 1);
  331. //pyfcgi_log(LOG_DEBUG, "Worker[%d] req #%d piper", wrk_id, req_id);
  332. fds[0].fd = pystderr;
  333. fds[1].fd = pystdout;
  334. fds[0].events = fds[1].events = POLLIN;
  335. fds[0].revents = fds[1].revents = 0;
  336. nfds = 2;
  337. closed = out_sz = 0;
  338. cont = 2;
  339. while(cont)
  340. {
  341. poll_ret = poll(fds, nfds, 0);
  342. //pyfcgi_log(LOG_DEBUG, "Worker[%d] req #%d poll_ret = %d", wrk_id, req_id, poll_ret);
  343. if(poll_ret < 0)
  344. {
  345. err = errno;
  346. if(err == EINTR)
  347. {
  348. continue;
  349. }
  350. pyfcgi_log( LOG_WARNING, "Poll error : %s",
  351. strerror(err));
  352. fds[0].revents = fds[1].revents = 0;
  353. continue;
  354. }
  355. if(!poll_ret && worker_piper_sigrcv)
  356. {
  357. cont--;
  358. continue;
  359. }
  360. if(poll_ret && (revents = fds[1].revents))
  361. {
  362. /*
  363. pyfcgi_log(LOG_DEBUG, "Worker[%d] req #%d STDOUT evt !",
  364. wrk_id, req_id);
  365. */
  366. poll_ret--;
  367. if(revents & POLLIN)
  368. {
  369. /*
  370. pyfcgi_log(LOG_DEBUG, "Worker[%d] req #%d POLLIN STDOUT !",
  371. wrk_id, req_id);
  372. */
  373. ret = read(pystdout, buf, PIPE_BUF);
  374. /*
  375. pyfcgi_log(LOG_DEBUG, "Worker[%d] req #%d read(stdout) ret %d",
  376. wrk_id, req_id, ret);
  377. */
  378. if(ret < 0)
  379. {
  380. err = errno;
  381. if(err == EINTR)
  382. {
  383. continue;
  384. }
  385. pyfcgi_log( LOG_ERR,
  386. "Error reading python stdout : %s",
  387. strerror(err));
  388. exit(err);
  389. }
  390. //buf[ret] = '\0';
  391. ret = FCGX_PutStr(buf, ret, out);
  392. out_sz += ret;
  393. if(ret < PIPE_BUF && worker_piper_sigrcv)
  394. {
  395. FCGX_FClose(out);
  396. FCGI_Finish();
  397. write(ctl_pipe, &out_sz, sizeof(size_t));
  398. closed = 1;
  399. nfds = 1;
  400. }
  401. }
  402. //TODO handle other poll events
  403. }
  404. if(poll_ret && (revents = fds[0].revents))
  405. {
  406. /*
  407. pyfcgi_log(LOG_DEBUG, "Worker[%d] req #%d STDERR evt !",
  408. wrk_id, req_id);
  409. */
  410. if(revents & POLLIN)
  411. {
  412. /*
  413. pyfcgi_log(LOG_DEBUG, "Worker[%d] req #%d POLLIN STDERR !",
  414. wrk_id, req_id);
  415. */
  416. while(1)
  417. {
  418. ret = read(pystderr, buf, PIPE_BUF);
  419. if(ret < 0)
  420. {
  421. err = errno;
  422. if(err == EINTR)
  423. {
  424. continue;
  425. }
  426. pyfcgi_log( LOG_ERR,
  427. "Error reading python stdout : %s",
  428. strerror(err));
  429. exit(err);
  430. }
  431. buf[ret] = '\0';
  432. pyfcgi_log(LOG_ERR,
  433. "Worker[%d] Python error : %s",
  434. wrk_id, buf);
  435. break;
  436. }
  437. }
  438. //TODO handle other poll events
  439. }
  440. fds[0].revents = fds[1].revents = 0;
  441. }
  442. /*
  443. pyfcgi_log(LOG_DEBUG, "Worker[%d] req #%d piper exiting...",
  444. wrk_id, req_id);
  445. */
  446. if(!closed)
  447. {
  448. FCGX_FClose(out);
  449. FCGI_Finish();
  450. write(ctl_pipe, &out_sz, sizeof(size_t));
  451. }
  452. return 0;
  453. }
  454. void worker_log_pipes(int pipe_std, int pipe_err, PyObject *flush[2])
  455. {
  456. size_t ret;
  457. char buff[4096];
  458. int i, poll_ret;
  459. int loglevels[2] = {LOG_INFO, LOG_WARNING};
  460. struct pollfd fds[2];
  461. short isflush[2] = {0,0};
  462. char *outnames[2] = {"sys.stdout", "sys.stderr"};
  463. fds[0].fd = pipe_std;
  464. fds[1].fd = pipe_err;
  465. fds[0].events = fds[1].events = POLLIN;
  466. fds[0].revents = fds[1].revents = 0;
  467. for(i=0; i<2; i++)
  468. {
  469. do
  470. {
  471. poll_ret = poll(&(fds[i]), 1, 0);
  472. if(poll_ret)
  473. {
  474. ret = read(pipe_std, buff, 4096);
  475. if(ret == -1)
  476. {
  477. pyfcgi_log(LOG_ERR, "Error reading python %s pipe : %s",
  478. outnames[i], strerror(errno));
  479. exit(PYFCGI_WORKER_FAIL);
  480. }
  481. pyfcgi_log(loglevels[i], "Pyton %s : '%s'",
  482. outnames[i], buff);
  483. }
  484. if(!isflush[i] && (!poll_ret || ret < 4096))
  485. {
  486. isflush[i] = 1;
  487. PyObject_CallObject(flush[i], NULL);
  488. if(PyErr_Occurred())
  489. {
  490. pyfcgi_log(LOG_ERR, "Exception while flushing %s",
  491. outnames[i]);
  492. log_expt(LOG_ERR);
  493. exit(PYFCGI_WORKER_FAIL);
  494. }
  495. }
  496. }while(poll_ret && !isflush[i]);
  497. }
  498. }
  499. void worker_piper_sighandler(int signum)
  500. {
  501. worker_piper_sigrcv = 1;
  502. //pyfcgi_log(LOG_DEBUG, "SIG");
  503. }
  504. int ctl_get_rep_sz(int ctl_pipe, size_t* rep_sz)
  505. {
  506. struct pollfd fds;
  507. int ret, err;
  508. fds.fd = ctl_pipe;
  509. fds.events = POLLIN;
  510. fds.revents = 0;
  511. if( (ret = poll(&fds, 1, 0)) < 0)
  512. {
  513. err = errno;
  514. pyfcgi_log(LOG_ERR, "Failed to poll ctl pipe : %s",
  515. strerror(err));
  516. return -1;
  517. }
  518. if(!ret)
  519. {
  520. pyfcgi_log(LOG_ERR, "No data in ctl pipe for rep_sz...");
  521. return -1;
  522. }
  523. ret = read(ctl_pipe, rep_sz, sizeof(size_t));
  524. if(ret < 0)
  525. {
  526. pyfcgi_log(LOG_ERR, "Error reading ctl pipe : %s",
  527. strerror(errno));
  528. return -1;
  529. }
  530. if(ret < sizeof(size_t))
  531. {
  532. pyfcgi_log(LOG_ERR, "Incomplete read from ctl pipe, no rep_sz...");
  533. return -1;
  534. }
  535. return 0;
  536. }
  537. static void worker_set_idle()
  538. {
  539. int err;
  540. if(_worker_idle) { return; }
  541. if(sem_post(PyFCGI_SEM(SEM_WSTATE).sem) < 0)
  542. {
  543. err = errno;
  544. pyfcgi_log(LOG_ERR, "error incrementing the WSTATE semaphore : %s",
  545. strerror(err));
  546. return;
  547. }
  548. _worker_idle = 1;
  549. }
  550. static void worker_set_busy()
  551. {
  552. int err;
  553. if(!_worker_idle) { return; }
  554. /**@todo The pool handler WILL decrement the sem to figure if the pool
  555. * is busy -__- Using sem_wait make sure that the worker will be able
  556. * to set busy, but it can also freeze if not able to set busy....
  557. * sem_timedwait require to get abstime -_- The better way is
  558. * maybe to nanosleep 0.01s and retry a sem_trywait... SysV sem are
  559. * better T_T
  560. */
  561. #ifdef DEBUG
  562. if(sem_trywait(PyFCGI_SEM(SEM_WSTATE).sem) < 0)
  563. #else
  564. if(sem_wait(PyFCGI_SEM(SEM_WSTATE).sem) < 0)
  565. #endif
  566. {
  567. err = errno;
  568. if(err == EAGAIN)
  569. { //panic
  570. pyfcgi_log(LOG_ALERT, "Unable to set busy ! WSTATE sem is allready 0 !!!");
  571. _worker_idle = 0;
  572. return;
  573. }
  574. pyfcgi_log(LOG_ERR, "error decrementing the WSTATE semaphore : %s",
  575. strerror(err));
  576. return;
  577. }
  578. _worker_idle = 0;
  579. }
  580. void worker_sighandler(int signum)
  581. {
  582. pyfcgi_log(LOG_INFO, "%s signal received, exiting...", strsignal(signum));
  583. worker_set_busy();
  584. pyfcgi_IPC_close(IPC_WSTATE | IPC_WREQS);
  585. exit(0);
  586. }
  587. void worker_sigalrmhandler(int signum)
  588. {
  589. _wtimeout = 1;
  590. if(!_worker_idle)
  591. {
  592. // Call PyErr_Interrupt() in order to stop python
  593. PyErr_SetInterrupt();
  594. }
  595. worker_set_busy();
  596. pyfcgi_IPC_close(IPC_WSTATE | IPC_WREQS);
  597. return;
  598. }