* store 保存变量,下次直接载入,方便调试
In [1]: l = ['hello',10,'world']
In [2]: %store l
In [3]: exit
(IPython session is closed and started again...)
ville@badger:~$ ipython
In [1]: l
NameError: name 'l' is not defined
In [2]: %store -r
In [3]: l
Out[3]: ['hello', 10, 'world']
* save file X-Y
保存X-Y行
* python/ipython交互模式历史记录搜索
$cat ~/.inputrc
## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward
In [7]: def a():
...: """ python docs goes here """
...: print 'Hi'
...:
In [8]: a?
Type: function
String form: <function a at 0x101b7be60>
File: /Users/ldong/GDrive/github/icebucket/ui/app/assets/<ipython-input-7-d7491bd3f1a8>
Definition: a()
Docstring: python docs goes here
In [10]: a??
Type: function
String form: <function a at 0x101b7be60>
File: /Users/ldong/GDrive/github/icebucket/ui/app/assets/<ipython-input-7-d7491bd3f1a8>
Definition: a()
Source:
def a():
""" python docs goes here """
print 'Hi'
```
i.e.
```python
In [18]: _i7
Out[18]: u'def a():\n """ python docs goes here """\n print \'Hi\'\n'
In [11]: a = 1
In [12]: _i11
Out[12]: u'a = 1'
```
注释用;
[unix_http_server]
file=/home/duoduo/supervisor/supervisor.sock ; (the path to the socket file)
文档中有这一句
If the configuration file has no [unix_http_server] section,
a UNIX domain socket HTTP server will not be started.
[supervisord]
定义这个supervisord的pid log等
[rpcinterface:supervisor](使用supervisorctl需要copy此段)
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl](想用supervisorctl的话必填)
注意serverurl应与unix_http_server的file地址对应
这样使得supervisorctl可以与supervisord通过相同的socket通信
(unix domain socket, 见上方链接)
serverurl=unix:///home/duoduo/supervisor/supervisor.sock
[program:name] 定义一个program,配置是自解释的
#! /usr/bin/env python
# This script requires that you have watchdog installed. You can install
# watchdog via 'pip install watchdog'
import sys
import time
import logging
import os
from subprocess import Popen
from signal import SIGTERM
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler, FileSystemEventHandler
# To watch more (or more specific) directories, change WATCH_DIRS to include the
# directories you want to watch. Note that this is recursive. If you want to
# watch fewer or more extensions, you can change EXTENSIONS. To watch all
# extensions, add "*" to EXTENSIONS.
WATCH_DIRS = ["../data", "common/lib/xmodule/xmodule/js", "common/lib/xmodule/xmodule/css"]
EXTENSIONS = ["*", "xml", "js", "css", "coffee", "scss", "html"]
WATCH_DIRS = [os.path.abspath(os.path.normpath(dir)) for dir in WATCH_DIRS]
class DjangoEventHandler(FileSystemEventHandler):
def __init__(self, process):
super(DjangoEventHandler, self).__init__()
self.process = process
def on_any_event(self, event):
for extension in EXTENSIONS:
if event.src_path.endswith(extension) or extension == "*":
print "%s changed: restarting server." % event.src_path
os.system("touch lms/__init__.py")
break
if __name__ == "__main__":
event_handler = DjangoEventHandler(Popen(['rake', 'lms']))
observer = Observer()
for dir in WATCH_DIRS:
observer.schedule(event_handler, dir, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()