Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sjrpc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
sjrpc
Commits
faf1306a
Commit
faf1306a
authored
13 years ago
by
Antoine Millet
Browse files
Options
Downloads
Patches
Plain Diff
Fixed shutdown RpcConnection memory leak problem with RpcServer
parent
c7a7ad8f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sjrpc/server/simple.py
+16
-4
16 additions, 4 deletions
sjrpc/server/simple.py
with
16 additions
and
4 deletions
sjrpc/server/simple.py
+
16
−
4
View file @
faf1306a
import
gc
import
ssl
import
time
import
errno
import
socket
import
select
import
weakref
import
logging
import
threading
from
sjrpc.core
import
RpcConnection
import
pyev
...
...
@@ -62,6 +62,16 @@ class RpcServer(object):
conn
=
self
.
_wrap
(
sock
)
self
.
register
(
conn
)
def
_clean_conn
(
self
,
ref
):
'''
Callback called by weakref when an object is about to be collected by
garbage collector.
'''
try
:
self
.
_clients
.
remove
(
ref
)
except
KeyError
:
pass
#
# Public methods:
#
...
...
@@ -72,7 +82,10 @@ class RpcServer(object):
:param conn: the connection to register.
'''
self
.
_clients
.
add
(
conn
)
self
.
_clients
.
add
(
weakref
.
ref
(
conn
,
self
.
_clean_conn
))
gc
.
collect
()
# Force a manual garbage collection to avoid memory leak
# with RpcConnections. This is maybe not required but I
# need to read docs about python's gc and circular refs.
def
unregister
(
self
,
conn
,
shutdown
=
False
):
'''
...
...
@@ -85,7 +98,6 @@ class RpcServer(object):
if
conn
in
self
.
_clients
:
if
shutdown
:
conn
.
shutdown
()
self
.
_clients
.
remove
(
conn
)
def
run
(
self
):
'''
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment