|
@@ -20,6 +20,8 @@
|
20
|
20
|
#include "pyworker.h"
|
21
|
21
|
|
22
|
22
|
|
|
23
|
+/**@brief 1 if worker idle else 0 */
|
|
24
|
+static short _worker_idle;
|
23
|
25
|
/**@brief Indicate that a worker is idle */
|
24
|
26
|
static inline void worker_set_idle();
|
25
|
27
|
/**@brief Indicate that a worker is busy */
|
|
@@ -61,17 +63,16 @@ int work333(int wrk_id)
|
61
|
63
|
pyfcgi_log(LOG_INFO, "Waiting request with %s.%s()",
|
62
|
64
|
PyFCGI_conf.py_entrymod, PyFCGI_conf.py_entryfun);
|
63
|
65
|
|
64
|
|
- worker_set_idle(); //before failing on import
|
65
|
|
-
|
66
|
66
|
if(!entry_fun) //but exit if import failed
|
67
|
67
|
{
|
68
|
68
|
pyfcgi_log(LOG_ALERT, "Unable to import entrypoint");
|
69
|
69
|
exit(PYFCGI_FATAL);
|
70
|
|
-
|
71
|
70
|
}
|
72
|
71
|
|
73
|
72
|
start_response = get_start_response();
|
74
|
73
|
|
|
74
|
+ _worker_idle = 0;
|
|
75
|
+ worker_set_idle();
|
75
|
76
|
// requests accepting loop
|
76
|
77
|
count = 0;
|
77
|
78
|
while ((!count || count != max_reqs) &&
|
|
@@ -121,7 +122,7 @@ int work333(int wrk_id)
|
121
|
122
|
FCGX_FClose(in_stream);
|
122
|
123
|
FCGX_FClose(err_stream);
|
123
|
124
|
FCGI_Finish();
|
124
|
|
- worker_set_idle();
|
|
125
|
+
|
125
|
126
|
gettimeofday(&stop, NULL);
|
126
|
127
|
stop.tv_sec = stop.tv_sec - start.tv_sec;
|
127
|
128
|
stop.tv_usec = stop.tv_usec - start.tv_usec;
|
|
@@ -133,7 +134,10 @@ int work333(int wrk_id)
|
133
|
134
|
pyfcgi_wd_pause();
|
134
|
135
|
pyfcgi_log(LOG_DEBUG, "Worker[%d] request %d END [OK] %lu bytes in %ld.%06lds",
|
135
|
136
|
wrk_id, count, libpyfcgi.rep_sz, stop.tv_sec, stop.tv_usec);
|
|
137
|
+
|
|
138
|
+ worker_set_idle();
|
136
|
139
|
}
|
|
140
|
+ worker_set_busy();
|
137
|
141
|
return 0;
|
138
|
142
|
}
|
139
|
143
|
|
|
@@ -207,7 +211,6 @@ int work(int wrk_id)
|
207
|
211
|
PyFCGI_conf.py_entrymod, PyFCGI_conf.py_entryfun);
|
208
|
212
|
|
209
|
213
|
|
210
|
|
- worker_set_idle(); //before failing on import
|
211
|
214
|
|
212
|
215
|
if(!entry_fun) //but exit if import failed
|
213
|
216
|
{
|
|
@@ -226,6 +229,9 @@ int work(int wrk_id)
|
226
|
229
|
}
|
227
|
230
|
piper_args.ctl_pipe = pipe_ctl[1];
|
228
|
231
|
|
|
232
|
+ _worker_idle = 0;
|
|
233
|
+ worker_set_idle();
|
|
234
|
+
|
229
|
235
|
count = 0;
|
230
|
236
|
while ((!count || count != max_reqs) && FCGX_Accept(&in_stream, &out_stream, &err_stream, &envp) >= 0)
|
231
|
237
|
{
|
|
@@ -310,6 +316,7 @@ int work(int wrk_id)
|
310
|
316
|
pyfcgi_log(LOG_DEBUG, "Worker[%d] request %d END [OK] %lu bytes in %ld.%06lds",
|
311
|
317
|
wrk_id, count, rep_sz, stop.tv_sec, stop.tv_usec);
|
312
|
318
|
}
|
|
319
|
+ worker_set_busy();
|
313
|
320
|
free(piper_stack);
|
314
|
321
|
Py_Exit(count == max_reqs ?0:EXIT_PYERR);
|
315
|
322
|
}
|
|
@@ -572,6 +579,8 @@ static void worker_set_idle()
|
572
|
579
|
int err;
|
573
|
580
|
struct sembuf sop;
|
574
|
581
|
|
|
582
|
+ if(_worker_idle) { return; }
|
|
583
|
+
|
575
|
584
|
sop.sem_num = 0;
|
576
|
585
|
sop.sem_flg = 0;
|
577
|
586
|
sop.sem_op = 1;
|
|
@@ -581,7 +590,9 @@ static void worker_set_idle()
|
581
|
590
|
err = errno;
|
582
|
591
|
pyfcgi_log(LOG_ERR, "error incrementing the semaphore : %s",
|
583
|
592
|
strerror(err));
|
|
593
|
+ return;
|
584
|
594
|
}
|
|
595
|
+ _worker_idle = 1;
|
585
|
596
|
}
|
586
|
597
|
|
587
|
598
|
static void worker_set_busy()
|
|
@@ -589,6 +600,8 @@ static void worker_set_busy()
|
589
|
600
|
int err;
|
590
|
601
|
struct sembuf sop;
|
591
|
602
|
|
|
603
|
+ if(!_worker_idle) { return; }
|
|
604
|
+
|
592
|
605
|
sop.sem_num = 0;
|
593
|
606
|
sop.sem_flg = 0;
|
594
|
607
|
sop.sem_op = -1;
|
|
@@ -598,17 +611,21 @@ static void worker_set_busy()
|
598
|
611
|
err = errno;
|
599
|
612
|
pyfcgi_log(LOG_ERR, "error incrementing the semaphore : %s",
|
600
|
613
|
strerror(err));
|
|
614
|
+ return;
|
601
|
615
|
}
|
|
616
|
+ _worker_idle = 0;
|
602
|
617
|
}
|
603
|
618
|
|
604
|
619
|
void worker_sighandler(int signum)
|
605
|
620
|
{
|
606
|
621
|
pyfcgi_log(LOG_INFO, "%s signal received, exiting...", strsignal(signum));
|
|
622
|
+ worker_set_busy();
|
607
|
623
|
exit(0);
|
608
|
624
|
}
|
609
|
625
|
|
610
|
626
|
void worker_sigalrmhandler(int signum)
|
611
|
627
|
{
|
612
|
|
- pyfcgi_log(LOG_WARNING, "Timeout, exiting...");
|
|
628
|
+ //pyfcgi_log(LOG_WARNING, "Timeout, exiting...");
|
|
629
|
+ worker_set_busy();
|
613
|
630
|
exit(PYFCGI_TIMEOUT);
|
614
|
631
|
}
|