Hi Folks:

I was testing a simple echoserver with stackless python 2.5.2 and pypy-c. I am 
running Ubuntu 9.04 and I compiled pypy-c with --stackless and optimization 
level 1.

Under stackless python, the echoserver executes correctly. Under pypy-c, the 
server runs a while before I get:

_scheduler_switch(curr, task)
  File "/home/andrew/lab/pypy-dist/pypy/lib/stackless.py", line 156, in 
_scheduler_switch
    next.switch()
  File "/home/andrew/lab/pypy-dist/pypy/lib/stackless.py", line 452, in _func
    func(*argl, **argd)
  File "/home/andrew/lab/pypy-dist/lib-python/2.5.2/stacklesssocket.py", line 
77, in ManageSockets
    asyncore.poll(0.05)
  File "/home/andrew/lab/pypy-dist/lib-python/2.5.2/asyncore.py", line 109, in 
poll
    is_r = obj.readable()
ReferenceError: weakly referenced object no longer exists

I am using the stacklesssocket.py from 

http://stacklessexamples.googlecode.com/svn/trunk/examples/networking/stacklesssocket.py

I have also enclosed the echoserver.py and a small test driver.py written with 
Twisted. I believe one can also use the drivers that come with the Beazley 
talk: http://www.dabeaz.com/coroutines/blaster.py

Meanwhile I am looking over stacklesssocket.py to understand the logic. That 
said, any suggestions would be appreciated.

Cheers,
Andrew


      
import sys, time
import stackless
import stacklesssocket

stacklesssocket.install()
import socket

def handle_client(client, addr):
    #print "connection from", addr
    while (True):
        data = client.recv(65536)
        if not data:
           break
        client.send(data)
    #print "client closed"
    client.close()


def server(port):
    print "server starting"
    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    serversocket.bind(port)
    serversocket.listen(5)

    while True:
           (client, addr) = serversocket.accept()
           stackless.tasklet(handle_client)(client, addr)


stackless.tasklet(server)(('127.0.0.1',8001))
stackless.run()
import time
from   twisted.internet import reactor, protocol


# a client protocol

errors = 0
connections = 100
count = 0
startTime = 0

def shouldFinish(error = 0):
     global errors
     global count
     global startTime

     count += 1

     if error:
        errors += 1

     if count >= connections:
        reactor.stop() 
        print connections, errors, time.time() - startTime


class EchoClient(protocol.Protocol):
    """Once connected, send a message, then print the result."""
    
    def connectionMade(self):
        self.transport.write("hello, world!")
    
    def dataReceived(self, data):
        "As soon as any data is received, write it back."
        print "Server said:", data
        self.transport.loseConnection()
    
    def connectionLost(self, reason):
        pass
        #print "connection lost"


class EchoFactory(protocol.ClientFactory):
    protocol = EchoClient

    def clientConnectionFailed(self, connector, reason):
        print "Connection failed - goodbye!"
        shouldFinish(1)
    
    def clientConnectionLost(self, connector, reason):
        #print "Connection lost - goodbye!"
        shouldFinish()


# this connects the protocol to a server runing on port 8000
def main():
    global startTime
    startTime = time.time()
    f = EchoFactory()
    for i in range(0,connections):
        reactor.connectTCP("localhost", 8001, f)
    reactor.run()

# this only runs if the module was *not* imported
if __name__ == '__main__':
    main()

Attachment: problems
Description: Binary data

_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev

Reply via email to