Ben Udp bükülmüş sunucu yazdım ve şu komutla koştum:Twisted sunucu çöküyor bir gün sonra
nohup python Udpserver2.py &
İlk başta iyi gitti, ama bir hata getirdi ve 1 gün sonra çöktü. nohup.out
hata bilgileri geçerli:
Unhandled Error
Traceback (most recent call last):
File "/usr/lib64/python2.7/site-packages/Twisted-15.4.0-py2.7-linux-x86_64.egg/twisted/python/log.py", line 84, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/lib64/python2.7/site-packages/Twisted-15.4.0-py2.7-linux-x86_64.egg/twisted/python/context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/lib64/python2.7/site-packages/Twisted-15.4.0-py2.7-linux-x86_64.egg/twisted/python/context.py", line 81, in callWithContext
return func(*args,**kw)
File "/usr/lib64/python2.7/site-packages/Twisted-15.4.0-py2.7-linux-x86_64.egg/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
why = selectable.doRead()
--- <exception caught here> ---
File "/usr/lib64/python2.7/site-packages/Twisted-15.4.0-py2.7-linux-x86_64.egg/twisted/internet/udp.py", line 248, in doRead
self.protocol.datagramReceived(data, addr)
File "UdpServer2.py", line 91, in datagramReceived
self.device_echo(data, str(host), int(port))
File "UdpServer2.py", line 19, in device_echo
cur.execute(sql)
File "/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')
Benim piton kodu UdpServer2.py
bu gibi yapılandırılmıştır:
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
import MySQLdb as mdb
conn = mdb.connect(host='localhost', user='root', passwd='123456', db='kj')
class KjEcho(DatagramProtocol):
def device_echo(self, msg, host, port):
device_no = msg[1:7]
sql = "select did from device where device_no='%s'" % (device_no)
cur = conn.cursor(mdb.cursors.DictCursor)
cur.execute(sql) #line 19 here
if 0 == cur.rowcount:
...
else:
...
cur.close()
def startProtocol(self):
print 'kj_udp_server starting...'
def datagramReceived(self, data, (host, port)):
print "receive msg"
if(18 != len(data)):
print 'len err'
return
if('0x86' != hex(ord(data[0]))):
print '0x86 err'
return
if(0 == ord(data[15])):
print 'from device'
self.device_echo(data, str(host), int(port)) #line 91 here
else:
print 'from mobile'
self.mobile_echo(data, str(host), int(port))
reactor.listenUDP(6000, KjEcho())
reactor.run()
Hat 91 ve hat 19 nedenleri sayesinde bunu düzeltmek için nasıl yukarıda belirtilen bulunmaktadır.
NOT: Makinenin bir yeri vardır, Her makinenin her 20 saniyede
Veritabanı sunucunuzun kullanılamadığı anlaşılıyor –
Hata, MySQL sunucunuzun kaybolup gitmediğini söylüyor ... – Mai