Ticket #36 (defect)

Opened 2 years ago

Last modified 2 years ago

Threads, openurl and memory usage

Status: closed (fixed)

Reported by: Sakya Assigned to: fraca7
Priority: major Component: documentation
Version: Keywords:
Cc:

Hi. Try this script

import thread
import pspnet, psp2d
import urllib
from pspos import freemem, getclock, setclock, getbus, setbus, battery 

gStatus = ""

def _connect(pCallback=None):
    try:
      pspnet.disconnectAPCTL()
    except:
      pass
    pspnet.connectToAPCTL(1, pCallback)


def connect(pCallback=None):
  thread.start_new_thread(_connect, (pCallback,))


def openURL(pURL):
  """Read from an URL"""
  global gStatus
  s = ""
  try:
    f = urllib.urlopen(pURL)
    s = f.read()  
    f.close()
  except IOError, msg:
    print "NET ERROR: ",
    print msg

  print "NET " + pURL + " = " + s
  gStatus = -1


#Main:
screen = psp2d.Screen()
font = psp2d.Font('font.png')
background_image = psp2d.Image(480,272)
background_image.clear(psp2d.Color(0,0,0))

def callback(status):
  global gStatus
  print status
  gStatus = status

connect(callback)
while True:
  screen.blit(background_image, 0, 0, background_image.width, background_image.height, 0, 0)
  font.drawText(screen, 20, 160, "STATUS: " + str(gStatus))
  newText = "MEM: " + str(freemem() / 1024) + "kb  CPU:" + str(getclock()) + "Mhz  BUS:" + str(getbus()) + "Mhz  BATT:" + str(battery()[3]) + "%"
  font.drawText(screen, 0, 0, newText)

  if gStatus == -1:
    #Leggo un indirizzo:
    thread.start_new_thread(openURL, ("http://ttpsponline.altervista.org/dummyServer.php?mod=status",))
    gStatus = 0
  screen.swap()

  pad = psp2d.Controller()
  if pad.cross:
    break

Every time the openURL function is called about 60kb are consumed. Can you understand why? And why the connectToAPCTL() locks my program even if launched as a new thread? :) Thanks

Change History

06/09/06 14:15:15: Modified by anonymous

  • summary changed from Threads & openurl and memory usage to Threads, openurl and memory usage.

06/12/06 10:13:07: Modified by Sakya

I've made some tests and the problem it's only the start_new_thread. Every time is called some kb are sonsumed.

09/26/06 16:04:30: Modified by fraca7

  • status changed from new to assigned.

I'm working on this.

10/02/06 11:15:17: Modified by fraca7

  • status changed from assigned to closed.
  • resolution set to fixed.

The fact that memory is consumed in start_new_thread is normal, each thread takes up some resources, but these weren't freed when the thread terminated. This is fixed.