Thread/Signal problem with threaded python app on 5.3

2005-02-09 Thread Payment Online
I have a client/server application written in python/twisted and on
freebsd 5.3 the server won't shut down correctly with SIGINT or
SIGTERM, instead requiring a SIGKILL.  The twist is that if I send the
server a signal, it will shut down on the next request from the
client.  In that case it shuts down immediately when the client
connects and closes the connection before it's fully established.

The server will also shut down correctly if it hasn't yet accepted any
connections from a client.

 This is on freebsd 5.3-release-p2 with python 2.4 and twisted both
installed from ports.  I am using the default libpthreads and python
is compiled to use threads.  I tested it on Debian (sarge) and the
signals work fine.

It's like there is some sort of event loop that isn't working
correctly.  Freebsd is obviously getting the signal, but it doesn't
act on it until another request comes in from the client.  Also for
those that aren't familiar with twisted this application opens a
thread for every request.

Below is some simple code that will run if you have twisted.  Sorry I
don't have a more simple test case, but I'm fairly new to python (and
threads), and writing something from scratch would take a while.

Server (save server to test.tac and start with twistd -noy test.tac)
---
from twisted.application import service,internet
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import defer, reactor
from twisted.python import threadable
from twisted.internet import threads
from twisted.python import log
threadable.init(1)
import sys

class ProcessTransaction:

  def Do(self,data):
  return 'Done'


### Protocol Implementation

class OT(Protocol):
def dataReceived(self, data):
  As soon as any data is received, process it in a thread.
  reactor.callLater(0, self.Start,data)

def PrintData(self,data):
  self.transport.write(%s\r\n % data)
  self.transport.loseConnection()

def Start(self,data):
  c = ProcessTransaction()
  d = threads.deferToThread(c.Do,data)
  d.addCallback(self.PrintData)
  d.addErrback(log.err)


application = service.Application(otransact)
OTService = service.IServiceCollection(application)
OTfactory = Factory()
OTfactory.protocol = OT
OTServer = internet.TCPServer(8000, OTfactory)
OTServer.setServiceParent(OTService)



Client (just run as python test.py)
--
import sys
import time

from twisted.internet.protocol import ClientFactory
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor

class EchoClient(LineReceiver):
end=GoodBye
def connectionMade(self):
self.sendLine(Testing)

def connectionLost(self, reason):
print 'connection lost (protocol)'
reactor.stop()

def lineReceived(self, line):
print receive:, line
self.transport.loseConnection()

class EchoClientFactory(ClientFactory):
protocol = EchoClient

def clientConnectionFailed(self, connector, reason):
print 'connection failed:', reason.getErrorMessage()
reactor.stop()

def clientConnectionLost(self, connector, reason):
print 'connection lost:', reason.getErrorMessage()
reactor.stop()


def main():
factory = EchoClientFactory()
reactor.connectTCP('localhost', 8000, factory)
reactor.run()


if __name__ == '__main__':
main()
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


5.3 release crash

2005-02-08 Thread Payment Online
I just had a 5.3-release-p2 box crash on me.  This box is in
production so I don't have any debugging information whatsoever. 
However, I'm hoping someone could tell me if what I think caused it is
possible/probable.

Not long before it crashed I was running some stress tests against a
new threaded server I was building in python by running 5-10 clients
simultaneously for about an hour.Since this box has been stable
for almost a year without any issues at all, I really doubt that it's
a coincidence.   Can anyone think of what issues with threads could
cause a panic?

Chris
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: 5.3 release crash

2005-02-08 Thread Payment Online
On Tue, 8 Feb 2005 09:57:19 -0800, Payment Online [EMAIL PROTECTED] wrote:
 I just had a 5.3-release-p2 box crash on me.  This box is in
 production so I don't have any debugging information whatsoever.
 However, I'm hoping someone could tell me if what I think caused it is
 possible/probable.
 
 Not long before it crashed I was running some stress tests against a
 new threaded server I was building in python by running 5-10 clients
 simultaneously for about an hour.Since this box has been stable
 for almost a year without any issues at all, I really doubt that it's
 a coincidence.   Can anyone think of what issues with threads could
 cause a panic?
 
 Chris
 
One more thing, the threaded application was running in a jail.  Not
sure if that could make any difference.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Python with threading core dumps on 5.3

2005-02-07 Thread Payment Online
I am consistantly getting seg faults and bus errors when running a
multi threaded python application under 5.3-release-p2.  Python was
built from the port(python 2.4) with threading enabled.  Rebuilding
with the huge stack size option enabled didn't make a difference.  The
application uses twisted (www.twistedmatrix.com) and it runs fine
until I put it under a bit of a load and have 20-30 simultaneous
threads running.  Then it core dumps.  Following is the backtrace from
the core file.  The backtrace is always the same.  Are threads just
generally problematic on Freebsd?

#0  0x2823cdbb in pthread_testcancel () from /usr/lib/libpthread.so.1
#1  0x28234b06 in pthread_mutexattr_init () from /usr/lib/libpthread.so.1
#2  0x in ?? ()
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Python with threading core dumps on 5.3

2005-02-07 Thread Payment Online
 
 You'll need to recompile with debugging symbols in order to get a
 useful trace.  The python maintainer might be able to talk you through
 this.

Ok I'll do that in a bit and post the results.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]