Browse Source

print RLIMIT_NOFILE

always close cymysql objects
dev
破娃酱 8 years ago
parent
commit
ac58020595
  1. 31
      db_transfer.py
  2. 3
      shadowsocks/server.py

31
db_transfer.py

@ -301,10 +301,20 @@ class DbTransfer(TransferBase):
user=self.cfg["user"], passwd=self.cfg["password"],
db=self.cfg["db"], charset='utf8')
try:
cur = conn.cursor()
try:
cur.execute(query_sql)
except Exception as e:
logging.error(e)
update_transfer = {}
cur.close()
conn.commit()
except Exception as e:
logging.error(e)
update_transfer = {}
conn.close()
return update_transfer
@ -321,8 +331,13 @@ class DbTransfer(TransferBase):
user=self.cfg["user"], passwd=self.cfg["password"],
db=self.cfg["db"], charset='utf8')
try:
rows = self.pull_db_users(conn)
except Exception as e:
logging.error(e)
rows = []
conn.close()
if not rows:
logging.warn('no user in db')
return rows
@ -414,19 +429,28 @@ class Dbv3Transfer(DbTransfer):
' END, t = ' + str(int(last_time)) + \
' WHERE port IN (%s)' % query_sub_in
cur = conn.cursor()
try:
cur.execute(query_sql)
except Exception as e:
logging.error(e)
cur.close()
try:
cur = conn.cursor()
try:
cur.execute("INSERT INTO `ss_node_online_log` (`id`, `node_id`, `online_user`, `log_time`) VALUES (NULL, '" + \
str(self.cfg["node_id"]) + "', '" + str(alive_user_count) + "', unix_timestamp()); ")
except Exception as e:
logging.error(e)
cur.close()
cur = conn.cursor()
try:
cur.execute("INSERT INTO `ss_node_info_log` (`id`, `node_id`, `uptime`, `load`, `log_time`) VALUES (NULL, '" + \
str(self.cfg["node_id"]) + "', '" + str(self.uptime()) + "', '" + \
str(self.load()) + "', unix_timestamp()); ")
except Exception as e:
logging.error(e)
cur.close()
except:
logging.warn('no `ss_node_online_log` or `ss_node_info_log` in db')
@ -444,8 +468,12 @@ class Dbv3Transfer(DbTransfer):
cur = conn.cursor()
node_info_keys = ['traffic_rate']
try:
cur.execute("SELECT " + ','.join(node_info_keys) +" FROM ss_node where `id`='" + str(self.cfg["node_id"]) + "'")
nodeinfo = cur.fetchone()
except Exception as e:
logging.error(e)
nodeinfo = None
if nodeinfo == None:
rows = []
@ -461,6 +489,7 @@ class Dbv3Transfer(DbTransfer):
self.cfg['transfer_mul'] = float(node_info_dict['traffic_rate'])
cur = conn.cursor()
try:
cur.execute("SELECT " + ','.join(keys) + " FROM user")
rows = []
for r in cur.fetchall():
@ -468,6 +497,8 @@ class Dbv3Transfer(DbTransfer):
for column in range(len(keys)):
d[keys[column]] = r[column]
rows.append(d)
except Exception as e:
logging.error(e)
cur.close()
return rows

3
shadowsocks/server.py

@ -41,6 +41,9 @@ def main():
daemon.daemon_exec(config)
import resource
logging.info('current process RLIMIT_NOFILE resource: soft %d hard %d' % resource.getrlimit(resource.RLIMIT_NOFILE))
if config['port_password']:
pass
else:

Loading…
Cancel
Save