Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
aa2e1af6
Commit
aa2e1af6
authored
Oct 05, 1999
by
Amos Latteier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Continued to tweak resource freeing code which should reduce leakage when errors occur.
parent
045432f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
94 deletions
+64
-94
ZServer/PCGIServer.py
ZServer/PCGIServer.py
+32
-47
lib/python/ZServer/PCGIServer.py
lib/python/ZServer/PCGIServer.py
+32
-47
No files found.
ZServer/PCGIServer.py
View file @
aa2e1af6
...
...
@@ -117,6 +117,7 @@ import DebugLogger
from
cStringIO
import
StringIO
from
tempfile
import
TemporaryFile
import
socket
,
string
,
os
,
sys
,
time
from
types
import
StringType
tz_for_log
=
compute_timezone_for_log
()
...
...
@@ -124,6 +125,8 @@ class PCGIChannel(asynchat.async_chat):
"""Processes a PCGI request by collecting the env and stdin and
then passing them to ZPublisher. The result is wrapped in a
producer and sent back."""
closed
=
0
def
__init__
(
self
,
server
,
sock
,
addr
):
self
.
server
=
server
...
...
@@ -175,9 +178,10 @@ class PCGIChannel(asynchat.async_chat):
string
.
strip
(
self
.
env
[
'PATH_INFO'
]),
'/'
))
self
.
env
[
'PATH_INFO'
]
=
'/'
+
string
.
join
(
path
[
len
(
script
):],
'/'
)
self
.
data
=
StringIO
()
DebugLogger
.
log
(
'B'
,
id
(
self
),
'%s %s'
%
(
self
.
env
[
'REQUEST_METHOD'
],
self
.
env
[
'PATH_INFO'
]))
'%s %s'
%
(
self
.
env
[
'REQUEST_METHOD'
],
self
.
env
.
get
(
'PATH_INFO'
,
'/'
)))
# now read the next size header
self
.
set_terminator
(
10
)
...
...
@@ -249,31 +253,14 @@ class PCGIChannel(asynchat.async_chat):
def
__repr__
(
self
):
return
"<PCGIChannel at %x>"
%
id
(
self
)
def
handle_close
(
self
):
def
close
(
self
):
self
.
closed
=
1
while
self
.
producer_fifo
:
p
=
self
.
producer_fifo
.
first
()
if
p
is
not
None
and
type
(
p
)
!=
StringType
:
p
.
more
()
# free up resources held by producer
self
.
producer_fifo
.
pop
()
self
.
close
()
def
handle_error
(
self
):
(
file
,
fun
,
line
),
t
,
v
,
tbinfo
=
compact_traceback
()
# sometimes a user repr method will crash.
try
:
self_repr
=
repr
(
self
)
except
:
self_repr
=
'<__repr__ (self) failed for object at %0x>'
%
id
(
self
)
self
.
log_info
(
'uncaptured python exception, closing channel %s (%s:%s %s)'
%
(
self_repr
,
t
,
v
,
tbinfo
),
'error'
)
self
.
handle_close
()
asyncore
.
dispatcher
.
close
(
self
)
class
PCGIServer
(
asyncore
.
dispatcher
):
...
...
@@ -405,7 +392,7 @@ class PCGIResponse(HTTPResponse):
self
.
stdout
.
write
(
str
(
self
))
self
.
_wrote
=
1
self
.
stdout
.
write
(
data
)
def
_finish
(
self
):
self
.
stdout
.
finish
(
self
)
self
.
stdout
.
close
()
...
...
@@ -434,27 +421,25 @@ class PCGIPipe:
self
.
_data
.
write
(
text
)
def
close
(
self
):
data
=
self
.
_data
.
getvalue
()
l
=
len
(
data
)
DebugLogger
.
log
(
'A'
,
id
(
self
.
_channel
),
'%s %s'
%
(
self
.
_channel
.
reply_code
,
l
))
self
.
_channel
.
push
(
'%010d%s%010d'
%
(
l
,
data
,
0
),
0
)
self
.
_channel
.
push
(
LoggingProducer
(
self
.
_channel
,
l
,
'log_request'
),
0
)
self
.
_channel
.
push
(
CallbackProducer
(
lambda
t
=
(
'E'
,
id
(
self
.
_channel
)):
apply
(
DebugLogger
.
log
,
t
)))
if
self
.
_shutdown
:
try
:
r
=
self
.
_shutdown
[
0
]
except
:
r
=
0
sys
.
ZServerExitCode
=
r
self
.
_channel
.
push
(
ShutdownProducer
(),
0
)
Wakeup
(
lambda
:
asyncore
.
close_all
())
else
:
self
.
_channel
.
push
(
None
,
0
)
Wakeup
()
if
not
self
.
_channel
.
closed
:
data
=
self
.
_data
.
getvalue
()
l
=
len
(
data
)
DebugLogger
.
log
(
'A'
,
id
(
self
.
_channel
),
'%s %s'
%
(
self
.
_channel
.
reply_code
,
l
))
self
.
_channel
.
push
(
'%010d%s%010d'
%
(
l
,
data
,
0
),
0
)
self
.
_channel
.
push
(
LoggingProducer
(
self
.
_channel
,
l
,
'log_request'
),
0
)
self
.
_channel
.
push
(
CallbackProducer
(
lambda
t
=
(
'E'
,
id
(
self
.
_channel
)):
apply
(
DebugLogger
.
log
,
t
)))
if
self
.
_shutdown
:
try
:
r
=
self
.
_shutdown
[
0
]
except
:
r
=
0
sys
.
ZServerExitCode
=
r
self
.
_channel
.
push
(
ShutdownProducer
(),
0
)
Wakeup
(
lambda
:
asyncore
.
close_all
())
else
:
self
.
_channel
.
push
(
None
,
0
)
Wakeup
()
self
.
_data
=
None
self
.
_channel
=
None
...
...
lib/python/ZServer/PCGIServer.py
View file @
aa2e1af6
...
...
@@ -117,6 +117,7 @@ import DebugLogger
from
cStringIO
import
StringIO
from
tempfile
import
TemporaryFile
import
socket
,
string
,
os
,
sys
,
time
from
types
import
StringType
tz_for_log
=
compute_timezone_for_log
()
...
...
@@ -124,6 +125,8 @@ class PCGIChannel(asynchat.async_chat):
"""Processes a PCGI request by collecting the env and stdin and
then passing them to ZPublisher. The result is wrapped in a
producer and sent back."""
closed
=
0
def
__init__
(
self
,
server
,
sock
,
addr
):
self
.
server
=
server
...
...
@@ -175,9 +178,10 @@ class PCGIChannel(asynchat.async_chat):
string
.
strip
(
self
.
env
[
'PATH_INFO'
]),
'/'
))
self
.
env
[
'PATH_INFO'
]
=
'/'
+
string
.
join
(
path
[
len
(
script
):],
'/'
)
self
.
data
=
StringIO
()
DebugLogger
.
log
(
'B'
,
id
(
self
),
'%s %s'
%
(
self
.
env
[
'REQUEST_METHOD'
],
self
.
env
[
'PATH_INFO'
]))
'%s %s'
%
(
self
.
env
[
'REQUEST_METHOD'
],
self
.
env
.
get
(
'PATH_INFO'
,
'/'
)))
# now read the next size header
self
.
set_terminator
(
10
)
...
...
@@ -249,31 +253,14 @@ class PCGIChannel(asynchat.async_chat):
def
__repr__
(
self
):
return
"<PCGIChannel at %x>"
%
id
(
self
)
def
handle_close
(
self
):
def
close
(
self
):
self
.
closed
=
1
while
self
.
producer_fifo
:
p
=
self
.
producer_fifo
.
first
()
if
p
is
not
None
and
type
(
p
)
!=
StringType
:
p
.
more
()
# free up resources held by producer
self
.
producer_fifo
.
pop
()
self
.
close
()
def
handle_error
(
self
):
(
file
,
fun
,
line
),
t
,
v
,
tbinfo
=
compact_traceback
()
# sometimes a user repr method will crash.
try
:
self_repr
=
repr
(
self
)
except
:
self_repr
=
'<__repr__ (self) failed for object at %0x>'
%
id
(
self
)
self
.
log_info
(
'uncaptured python exception, closing channel %s (%s:%s %s)'
%
(
self_repr
,
t
,
v
,
tbinfo
),
'error'
)
self
.
handle_close
()
asyncore
.
dispatcher
.
close
(
self
)
class
PCGIServer
(
asyncore
.
dispatcher
):
...
...
@@ -405,7 +392,7 @@ class PCGIResponse(HTTPResponse):
self
.
stdout
.
write
(
str
(
self
))
self
.
_wrote
=
1
self
.
stdout
.
write
(
data
)
def
_finish
(
self
):
self
.
stdout
.
finish
(
self
)
self
.
stdout
.
close
()
...
...
@@ -434,27 +421,25 @@ class PCGIPipe:
self
.
_data
.
write
(
text
)
def
close
(
self
):
data
=
self
.
_data
.
getvalue
()
l
=
len
(
data
)
DebugLogger
.
log
(
'A'
,
id
(
self
.
_channel
),
'%s %s'
%
(
self
.
_channel
.
reply_code
,
l
))
self
.
_channel
.
push
(
'%010d%s%010d'
%
(
l
,
data
,
0
),
0
)
self
.
_channel
.
push
(
LoggingProducer
(
self
.
_channel
,
l
,
'log_request'
),
0
)
self
.
_channel
.
push
(
CallbackProducer
(
lambda
t
=
(
'E'
,
id
(
self
.
_channel
)):
apply
(
DebugLogger
.
log
,
t
)))
if
self
.
_shutdown
:
try
:
r
=
self
.
_shutdown
[
0
]
except
:
r
=
0
sys
.
ZServerExitCode
=
r
self
.
_channel
.
push
(
ShutdownProducer
(),
0
)
Wakeup
(
lambda
:
asyncore
.
close_all
())
else
:
self
.
_channel
.
push
(
None
,
0
)
Wakeup
()
if
not
self
.
_channel
.
closed
:
data
=
self
.
_data
.
getvalue
()
l
=
len
(
data
)
DebugLogger
.
log
(
'A'
,
id
(
self
.
_channel
),
'%s %s'
%
(
self
.
_channel
.
reply_code
,
l
))
self
.
_channel
.
push
(
'%010d%s%010d'
%
(
l
,
data
,
0
),
0
)
self
.
_channel
.
push
(
LoggingProducer
(
self
.
_channel
,
l
,
'log_request'
),
0
)
self
.
_channel
.
push
(
CallbackProducer
(
lambda
t
=
(
'E'
,
id
(
self
.
_channel
)):
apply
(
DebugLogger
.
log
,
t
)))
if
self
.
_shutdown
:
try
:
r
=
self
.
_shutdown
[
0
]
except
:
r
=
0
sys
.
ZServerExitCode
=
r
self
.
_channel
.
push
(
ShutdownProducer
(),
0
)
Wakeup
(
lambda
:
asyncore
.
close_all
())
else
:
self
.
_channel
.
push
(
None
,
0
)
Wakeup
()
self
.
_data
=
None
self
.
_channel
=
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment