|
[Webware-discuss] Freeze at ThreadedAppServer
From: Alex Ivanov <a_shy@ma...> - 2012-10-05 08:29
|
Hello!
First of all, thank you, Christoph, for the excellent software! I've been using webware since 2002 and have not yet seen a decent replacement to it! Outstanding performance of lightweight servlets implementation leaves behind its competitors with their tons of useless code. That's the main feature I'm using from webware.
Upgraded recently to 1.1 and discovered a freeze when I press Ctrl+C. It happens only on Windows. I'm using Windows 7. Linux is not affected.
In fact the reason of the freeze seems to be quite simple:
ThreadedAppServer.py, line 1308:
t = Thread(target=_windowsmainloop)
t.start()
...
_windowsmainloop calls server.mainloop(), which flags self._running:
threadCheckInterval = self._maxServerThreads * 2
threadUpdateDivisor = 5 # grab stat interval
threadCheck = 0
---> self._running = 3 # server is in the main loop now
On subsequent check server._running is still 1 because the thread does not have enough time to initialize itself:
---> while server._running > 1:
try:
sleep(1) # wait for interrupt
except Exception:
if server._running < 3:
raise # shutdown
So, we skip waiting and freeze at an endless loop.
The fix may be the following:
ThreadedAppServer.py, line 1307:
# Run the server thread
t = Thread(target=_windowsmainloop)
t.start()
try:
---> # Inserting waiting loop before _running status check.
---> for i in range(30): # wait at most 3 seconds for startup
---> if server._running == 3:
---> break
---> sleep(0.1)
while server._running > 1:
try:
sleep(1) # wait for interrupt
except Exception:
if server._running < 3:
raise # shutdown
finally:
t.join()
Can you please confirm that this fix is applicable?
We may throw an exception if wait was not successful.
Will it be a good idea to rewrite flags usage with python's events wait/set functionality to be on the safe side?
Thank you very much,
Mikhail
|
| Thread | Author | Date | |
|---|---|---|---|
| [Webware-discuss] Freeze at ThreadedAppServer | Alex Ivanov <a_shy@ma...> |
|
|