fedora20远程桌面
2014年1月13日 16:05
通过代理远程登陆其它网段的机器,要以命令行方式启动远程桌面.
在fedora20以前,启动远程桌面的命令是rdesktop。目前的fedora20中未提供rdesktop,需要自己安装
[wyq@localhost workspace]$ sudo yum install rdesktop
或者使用vinagre命令启动
[wyq@localhost workspace]$ vinagre
通过代理远程登陆其它网段的机器,要以命令行方式启动远程桌面.
在fedora20以前,启动远程桌面的命令是rdesktop。目前的fedora20中未提供rdesktop,需要自己安装
[wyq@localhost workspace]$ sudo yum install rdesktop
或者使用vinagre命令启动
[wyq@localhost workspace]$ vinagre
import web def main(): db = web.database(port=5432, host='localhost', dbn='postgres', db='tax', user='postgres', pw='postgres') rs = db.query("select count(*) as count from pg_stat_activity") print list(rs)[0].count db.ctx.db.close() if __name__ == '__main__': main()
import time import web import psycopg2 def main(): db = web.database(port=5432, host='localhost', dbn='postgres', db='tax', user='postgres', pw='postgres') rs = db.query("select count(*) as count from pg_stat_activity") print list(rs)[0].count db.ctx.db.close() if __name__ == '__main__': while True: main() time.sleep(1)
import psycopg2 from DBUtils import PooledDB def main(): #mincached,maxconnections限制连接池中的连接数 pool = PooledDB.PooledDB(psycopg2, port=5432, host='localhost', dbname='postgres', database='tax', user='postgres', password='postgres', mincached=2, maxconnections=2) # 从连接池中取一个连接 conn = pool.connection() cur = conn.cursor() cur.execute("select count(*) as count from pg_stat_activity") rs = cur.fetchone() print list(rs) cur.close() # 不会影响这个连接池的连接数量. pool.close()关闭连接池,会关闭所有连接. conn.close() if __name__ == '__main__': while True: main() time.sleep(1)
class ThreadedDict(threadlocal): """ Thread local storage. >>> d = ThreadedDict() >>> d.x = 1 >>> d.x 1 >>> import threading >>> def f(): d.x = 2 ... >>> t = threading.Thread(target=f) >>> t.start() >>> t.join() >>> d.x 1 """ # 原因就在这里 _instances = set() def __init__(self): ThreadedDict._instances.add(self) def __del__(self): ThreadedDict._instances.remove(self) def __hash__(self): return id(self) ....
#encoding=utf-8 from threading import local, Thread, currentThread threadeddict = local() threadeddict.name = "main" ctx = {"username": "abc"} class LocalThread(Thread): def run(self): print "-----local-------" print currentThread() print threadeddict.__dict__ # 可以访问到主线程中的变量,但是访问不了它的内容 print ctx # 变量和内容都可以访问 threadeddict.name = self.getName() # 改变值不会影响主线程 print threadeddict.__dict__ if __name__ == '__main__': print "-----main-------" print currentThread() print threadeddict.__dict__ A = LocalThread() A.start() A.join() print "-----main-------" print currentThread() print threadeddict.__dict__
要求计算上月,并且返回格式为XX的
now = datetime.datetime.now() last = now - datetime.timedelta(days=now.day) print last.strftime('%m')
计算下个月
import calendar import datetime now = datetime.datetime.now() max_days = calendar.monthrange(now.year, now.month)[1] next = now + datetime.timedelta(days=max_days - now.day + 1) print next.strftime('%m')
安装psycopg2出现这个错误,需要安装postgresql-devel
sudo yum install postgresql-devel
安装包出现上面错误,是因为缺少python-devel
sudo yum install python-devel
经常使用ssh远程登录,每次都敲一长串字符。重复多了,有砸键盘的冲动。后来发现可用别名代替。
在~/.ssh/config 中加入以下内容
Host mt98 //快捷名 HostName 135.32.9.98 //主机名 User monitor //用户名
然后可用ssh mt98登陆
运行时出现错误
ssh: Could not resolve hostname mt98: Name or service not known
config文件需要改成和known_hosts的所有者一致.
使用错误的默认值,会掩盖错误,又造成新的错误,最后将错误传入内部。
# 前台传入三个参数,三个参数都是必需的. identifier = web.input().get("identifier", None) # webpy框架 year = web.input().get("year", None) taxpayer_name = web.input().get("taxpayer_name", None) # 传输如None参数,会导致接口出现错误 result = service.inquiryTaxOwe(identifier, year, taxpayer_name)
前台传入三个参数时,表现正常。
上面使用默认参数是demo阶段时为了方面。实现时会出现下面的情况.
identifier = web.input().identifier year = web.input().year taxpayer_name = web.input().taxpayer_name result = service.inquirytaxOwe(identifier, year, taxpayer_name)
再不传入参数时,会及早发现,不会再有上面的郁闷了.
在win8系统下运行 python -m SimpleHTTPServer 出现Traceback (most recent call last):
File "D:\Python27\lib\runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "D:\Python27\lib\runpy.py", line 72, in _run_code exec code in run_globals File "D:\Python27\lib\SimpleHTTPServer.py", line 27, in <module> class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): File "D:\Python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHand ler mimetypes.init() # try to read system mime.types File "D:\Python27\lib\mimetypes.py", line 358, in init db.read_windows_registry() File "D:\Python27\lib\mimetypes.py", line 258, in read_windows_registry for subkeyname in enum_types(hkcr): File "D:\Python27\lib\mimetypes.py", line 249, in enum_types ctype = ctype.encode(default_encoding) # omit in 3.x! UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)
在import SimpleHTTPServer时,同样出现上面的错误.
在import sys后面加上下面语句
reload(sys) sys.setdefaultencoding('gbk')