Skip to content

Commit

Permalink
Fixed #5486 -- Worked around the lack of os.getpid() in Jython, whils…
Browse files Browse the repository at this point in the history
…t still using it for CPython. Patch from Leo Soto.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6270 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Sep 15, 2007
1 parent 1baae32 commit cd8959c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion django/contrib/sessions/models.py
Expand Up @@ -15,8 +15,13 @@ def get_new_session_key(self):
"Returns session key that isn't being used." "Returns session key that isn't being used."
# The random module is seeded when this Apache child is created. # The random module is seeded when this Apache child is created.
# Use SECRET_KEY as added salt. # Use SECRET_KEY as added salt.
try:
pid = os.getpid()
except AttributeError:
# No getpid() in Jython, for example
pid = 1
while 1: while 1:
session_key = md5.new("%s%s%s%s" % (random.randint(0, sys.maxint - 1), os.getpid(), time.time(), settings.SECRET_KEY)).hexdigest() session_key = md5.new("%s%s%s%s" % (random.randint(0, sys.maxint - 1), pid, time.time(), settings.SECRET_KEY)).hexdigest()
try: try:
self.get(session_key=session_key) self.get(session_key=session_key)
except self.model.DoesNotExist: except self.model.DoesNotExist:
Expand Down
6 changes: 5 additions & 1 deletion django/core/mail.py
Expand Up @@ -50,7 +50,11 @@ def make_msgid(idstring=None):
""" """
timeval = time.time() timeval = time.time()
utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval)) utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval))
pid = os.getpid() try:
pid = os.getpid()
except AttributeError:
# Not getpid() in Jython, for example.
pid = 1
randint = random.randrange(100000) randint = random.randrange(100000)
if idstring is None: if idstring is None:
idstring = '' idstring = ''
Expand Down

0 comments on commit cd8959c

Please sign in to comment.