Weird MemoryError issue

2006-07-19 Thread jedi200581
Hi,

  I'm new at python as I just started to learn it, but I found out
something weird. I have wrote a little program to compute Mersenne
number:

# Snipet on
def is_prime n:
  for i in range(2, n):
if (n % i) == 0:
  return 0
  else:
  return 1

for a in range(2, 1000):
  if (is_prime(a) and is_prime(2**a-1))
print 2**a-1, " is a prime number"
# Snipet off

This program raise MemoryError. But this one:

# Snipet on
def is_prime n:
  for i in range(2, n):
if (n % i) == 0:
  return 0
  return 1 # the change is here

for a in range(2, 1000):
  if (is_prime(a) and is_prime(2**a-1))
print 2**a-1, " is a prime number"
# Snipet off

Does not! Why ??

Thx.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Weird MemoryError issue

2006-07-19 Thread jedi200581

John Machin wrote:
> On 20/07/2006 6:05 AM, John Machin wrote:
> > On 20/07/2006 1:58 AM, [EMAIL PROTECTED] wrote:
> >> def is_prime n:
> >
> > Syntax error. Should be:
> >def is_prime n:
>
> Whoops! Take 2:
>
> Should be:
>
> def is_prime(n):

Sorry for that, I was not able to cut-paste the code at the moment, and
was in a hurry, I know it's bad.

Thanks for "xrange", I tried and it works fine.

-- 
http://mail.python.org/mailman/listinfo/python-list


Pygame, mouse events and threads

2006-08-24 Thread jedi200581
Hi,

  I'm trying to retreive mouse event in a python thread using pygame.
It's not working and I don't know why! Here is the code:



import pygame, sys, os, threading
from pygame.locals import *
from threading import *

class Display(Thread) :
  """Class managing display"""
  def __init__(self, xRes = 640, yRes = 480):
Thread.__init__(self)
#initializing display
self._xRes = xRes
self._yRes = yRes
pygame.display.init()
self._window = pygame.display.set_mode((xRes, yRes))
pygame.display.set_caption('Display')
self._screen = pygame.display.get_surface()
pygame.display.flip()

self._log = []
  def input(self, event):
if event.type == KEYDOWN:
  sys.exit(0)
else:
  print event
  def run(self):
print "starting event handling thread"
i = 0
while True:
  self.input(pygame.event.wait())

disp = Display()
disp.start()



When I put the content of the run and input functions in the main
thread, it's working, why not in the thread?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pygame, mouse events and threads

2006-08-24 Thread jedi200581

Ben Sizer wrote:
> [EMAIL PROTECTED] wrote:
>
> > When I put the content of the run and input functions in the main
> > thread, it's working, why not in the thread?
>
> Because event handling needs to be done in the main thread. So does
> rendering. This is a limitation of the underlying system.
>
> As a general rule, try to keep all your PyGame functions in the main
> thread and push your other processing into background threads, if you
> really need them.
>
> --
> Ben Sizer

Well, that is a limitation... And is it something that will be fixed or
something that is inherent to pygame and not fixable?

-- 
http://mail.python.org/mailman/listinfo/python-list