python gdb & pip install timeout & runlike

Python gdb
python -m pdb pytest.py
https://www.cnblogs.com/Jeffiy/p/4920019.html
import traceback
traceback.print_stack()

import pdb
pdb.set_trace()
1 perl -d ftcov.pl
https://www.cnblogs.com/xuxm2007/archive/2010/09/07/1820986.html 
pip list          查看pip安装的软件包名称及版本
pip show TA-Lib   查看TA-Lib的安装路径
pip intall timeout https://www.cnblogs.com/lowmanisbusy/p/12165829.html

默认情况下,pip 的默认源是 pypi.python.org,如果服务器是在国外,一般不会出现什么问题,如果服务器是在国内,在实际操作过程中发现,如果依赖包大一点

经常会出现 timeout 的情况,解决办法如下:

方法一,临时解决,pip 时,指定源:pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com  {依赖包的名称}

  个人感觉豆瓣的源还是比较快的

方法二,永久解决:  Linux

  1. 在用户家目录下创建或者修改 pip配置文件

    ~/.pip/pip.conf

  2. 将配置文件改成如下内容,可根据实际需求,替换成合适的源

[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors = true
mirrors = http://pypi.douban.com/simple
trusted-host = pypi.douban.com

SWIG and Python  http://www.swig.org/Doc1.3/Python.html#Python    describle how to wrap a module for python

2005 vi example.i
2006 vi example.c
2007 vi example.h
2008 swig -python example.i
2009 sudo apt install swig
2021 vi setup.py
2022 python setup.py build_ext --inplace

 1 moonx@moonx-G3-3590:/download/tmp$ cat testtcmalloc.cc 
 2 #include <stdlib.h>
 3 
 4 int main( int argc, char *argv[] )
 5 {   
 6   malloc(1);
 7 }
 8 moonx@moonx-G3-3590:/download/tmp$ 
 9 moonx@moonx-G3-3590:/download/tmp$ g++ -O0 -g testtcmalloc.cc -ltcmalloc  
10 moonx@moonx-G3-3590:/download/tmp$ gdb a.out 
11 GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
12 Copyright (C) 2016 Free Software Foundation, Inc.
13 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
14 This is free software: you are free to change and redistribute it.
15 There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
16 and "show warranty" for details.
17 This GDB was configured as "x86_64-linux-gnu".
18 Type "show configuration" for configuration details.
19 For bug reporting instructions, please see:
20 <http://www.gnu.org/software/gdb/bugs/>.
21 Find the GDB manual and other documentation resources online at:
22 <http://www.gnu.org/software/gdb/documentation/>.
23 For help, type "help".
24 Type "apropos word" to search for commands related to "word"...
25 Reading symbols from a.out...done.
26 (gdb) b main
27 Breakpoint 1 at 0x400675: file testtcmalloc.cc, line 5.
28 (gdb) r
29 Starting program: /download/tmp/a.out 
30 [Thread debugging using libthread_db enabled]
31 Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
32 
33 Breakpoint 1, main (argc=1, argv=0x7fffffffdc58) at testtcmalloc.cc:5
34 5      malloc(1);
35 (gdb) s
36 tc_malloc (size=1) at src/tcmalloc.cc:1899
37 1899      return malloc_fast_path<tcmalloc::malloc_oom>(size);
38 (gdb) quit
39 A debugging session is active.
40     Inferior 1 [process 32616] will be killed.
41 Quit anyway? (y or n) EOF [assumed Y]
42 排序居然比不排序还快,原来是 tcmalloc 出问题了 https://zhuanlan.zhihu.com/p/59437135
tcmalloc
  1 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 2342: ordinal not in range(128)
  2 
  3 sde@sde:~$ cat /usr/local/lib/python2.7/dist-packages/runlike/inspector.py
  4 import sys
  5 import re
  6 from subprocess import (
  7     check_output,
  8     STDOUT,
  9     CalledProcessError
 10 )
 11 from json import loads
 12 from pipes import quote
 13 
 14 
 15 def die(message):
 16     sys.stderr.write(message + "\n")
 17     sys.exit(1)
 18 
 19 
 20 class Inspector(object):
 21 
 22     def __init__(self, container, no_name, pretty):
 23         self.container = container
 24         self.no_name = no_name
 25         self.output = ""
 26         self.pretty = pretty
 27         self.facts = None
 28         self.options = []
 29 
 30     def inspect(self):
 31         if sys.getdefaultencoding() != 'utf-8':
 32             reload(sys)
 33             sys.setdefaultencoding('utf-8')
 34         try:
 35             output = check_output(
 36                 ["docker", "inspect", self.container],
 37                 stderr=STDOUT)
 38             self.facts = loads(output.decode())
 39         except CalledProcessError as e:
 40             if "No such image or container" in e.output:
 41                 die("No such container %s" % self.container)
 42             else:
 43                 die(str(e))
 44 
 45     def get_fact(self, path):
 46         parts = path.split(".")
 47         value = self.facts[0]
 48         for p in parts:
 49             if p not in value:
 50                 return None
 51             value = value[p]
 52         return value
 53 
 54     def multi_option(self, path, option):
 55         values = self.get_fact(path)
 56         if values:
 57             for val in values:
 58                 self.options.append('--%s=%s' % (option, quote(val)))
 59 
 60     def parse_hostname(self):
 61         hostname = self.get_fact("Config.Hostname")
 62         self.options.append("--hostname=%s" % hostname)
 63 
 64     def parse_user(self):
 65         user = self.get_fact("Config.User")
 66         if user != "":
 67             self.options.append("--user=%s" % user)
 68 
 69     def parse_macaddress(self):
 70         try:
 71             mac_address = self.get_fact("Config.MacAddress") or self.get_fact("NetworkSettings.MacAddress") or {}
 72             if mac_address:
 73                 self.options.append("--mac-address=%s" % mac_address)
 74         except Exception:
 75             pass
 76 
 77     def parse_ports(self):
 78         ports = self.get_fact("NetworkSettings.Ports") or {}
 79         ports.update(self.get_fact("HostConfig.PortBindings") or {})
 80 
 81         if ports:
 82             for container_port_and_protocol, options in ports.items():
 83                 if container_port_and_protocol.endswith("/tcp"):
 84                     container_port_and_protocol = container_port_and_protocol[:-4]
 85                 if options is not None:
 86                     host_ip = options[0]["HostIp"]
 87                     host_port = options[0]["HostPort"]
 88                     if host_port == "":
 89                         self.options.append("-p " + container_port_and_protocol)
 90                     else:
 91                         if host_ip != '':
 92                             self.options.append(
 93                                 '-p %s:%s:%s' %
 94                                 (host_ip, host_port, container_port_and_protocol))
 95                         else:
 96                             self.options.append(
 97                                 '-p %s:%s' %
 98                                 (host_port, container_port_and_protocol))
 99                 else:
100                     self.options.append(
101                         '--expose=%s' %
102                         container_port_and_protocol)
103 
104         exposed_ports = self.get_fact("Config.ExposedPorts")
105         if exposed_ports:
106             for container_port_and_protocol, options in exposed_ports.items():
107                 if not ports or container_port_and_protocol not in ports.keys():
108                     self.options.append(
109                         '--expose=%s' %
110                         container_port_and_protocol)
111 
112     def parse_links(self):
113         links = self.get_fact("HostConfig.Links")
114         link_options = set()
115         if links is not None:
116             for link in links:
117                 src, dst = link.split(":")
118                 dst = dst.split("/")[-1]
119                 src = src.split("/")[-1]
120                 if src != dst:
121                     link_options.add('--link %s:%s' % (src, dst))
122                 else:
123                     link_options.add('--link %s' % (src))
124 
125         self.options += list(link_options)
126 
127     def parse_restart(self):
128         restart = self.get_fact("HostConfig.RestartPolicy.Name")
129         if not restart:
130             return
131         elif restart == 'on-failure':
132             max_retries = self.get_fact(
133                 "HostConfig.RestartPolicy.MaximumRetryCount")
134             if max_retries > 0:
135                 restart += ":%d" % max_retries
136         self.options.append("--restart=%s" % restart)
137 
138     def parse_devices(self):
139         devices = self.get_fact("HostConfig.Devices")
140         if not devices:
141             return
142         device_options = set()
143         for device_spec in devices:
144             host = device_spec['PathOnHost']
145             container = device_spec['PathInContainer']
146             perms = device_spec['CgroupPermissions']
147             spec = '%s:%s' % (host, container)
148             if perms != 'rwm':
149                 spec += ":%s" % perms
150             device_options.add('--device %s' % (spec,))
151 
152         self.options += list(device_options)
153 
154     def parse_labels(self):
155         labels = self.get_fact("Config.Labels") or {}
156         label_options = set()
157         if labels is not None:
158             for key, value in labels.items():
159                 label_options.add("--label='%s=%s'" % (key, value))
160         self.options += list(label_options)
161 
162     def parse_log(self):
163         log_type = self.get_fact("HostConfig.LogConfig.Type")
164         log_opts = self.get_fact("HostConfig.LogConfig.Config") or {}
165         log_options = set()
166         if log_type != 'json-file':
167             log_options.add('--log-driver=%s' % log_type)
168         if log_opts:
169             for key, value in log_opts.items():
170                 log_options.add('--log-opt %s=%s' % (key, value))
171         self.options += list(log_options)
172 
173     def parse_extra_hosts(self):
174         hosts = self.get_fact("HostConfig.ExtraHosts") or []
175         self.options += ['--add-host %s' % host for host in hosts]
176 
177     def parse_workdir(self):
178         workdir = self.get_fact("Config.WorkingDir")
179         if workdir:
180             self.options.append("--workdir=%s" % workdir)
181 
182     def format_cli(self):
183         self.output = "docker run "
184 
185         image = self.get_fact("Config.Image")
186         self.options = []
187 
188         name = self.get_fact("Name").split("/")[1]
189         if not self.no_name:
190             self.options.append("--name=%s" % name)
191         self.parse_hostname()
192         self.parse_user()
193         self.parse_macaddress()
194 
195         self.multi_option("Config.Env", "env")
196         self.multi_option("HostConfig.Binds", "volume")
197         self.multi_option("Config.Volumes", "volume")
198         self.multi_option("HostConfig.VolumesFrom", "volumes-from")
199         self.multi_option("HostConfig.CapAdd", "cap-add")
200         self.multi_option("HostConfig.CapDrop", "cap-drop")
201         self.multi_option("HostConfig.Dns", "dns")
202         network_mode = self.get_fact("HostConfig.NetworkMode")
203         if network_mode != "default":
204             self.options.append("--network=" + network_mode)
205         privileged = self.get_fact('HostConfig.Privileged')
206         if privileged:
207             self.options.append("--privileged")
208 
209         self.parse_workdir()
210         self.parse_ports()
211         self.parse_links()
212         self.parse_restart()
213         self.parse_devices()
214         self.parse_labels()
215         self.parse_log()
216         self.parse_extra_hosts()
217 
218         stdout_attached = self.get_fact("Config.AttachStdout")
219         if not stdout_attached:
220             self.options.append("--detach=true")
221 
222         if self.get_fact("Config.Tty"):
223             self.options.append('-t')
224 
225         parameters = ["run"]
226         if self.options:
227             parameters += self.options
228         parameters.append(image)
229 
230         cmd_parts = self.get_fact("Config.Cmd")
231         if cmd_parts:
232             # NOTE: pipes.quote() performs syntactically correct
233             # quoting and replace operation below is needed just for
234             # aesthetic reasons and visual similarity with old output.
235             quoted = [
236                 quote(p).replace("'\"'\"'", r"\'")
237                 for p in cmd_parts
238             ]
239             command = " ".join(quoted)
240             parameters.append(command)
241 
242         joiner = " "
243         if self.pretty:
244             joiner += "\\\n\t"
245         parameters = joiner.join(parameters)
246 
247         return "docker %s" % parameters
248 sde@sde:~$ runlike -p gitlab
249 docker run \
250         --name=gitlab \
251         --hostname=10.18.1.2 \
252         --mac-address=02:42:ac:11:00:04 \
253         --env=PATH=/opt/gitlab/embedded/bin:/opt/gitlab/bin:/assets:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
254         --env=TERM=xterm \
255         --volume=/home/sde/gitlab/data:/var/opt/gitlab \
256         --volume=/home/sde/gitlab/config:/etc/gitlab \
257         --volume=/home/sde/gitlab/logs:/var/log/gitlab \
258         --volume=/var/opt/gitlab \
259         --volume=/etc/gitlab \
260         --volume=/var/log/gitlab \
261         -p 9999:9999 \
262         --expose=80 \
263         -p 8888:22 \
264         -p 443:443 \
265         --restart=no \
266         --detach=true \
267         gitlab/gitlab-ee:10.7.3-ee.0 \
268         /assets/wrapper
runlike:容器启动后,查看容器创建时的参数

posted on 2018-11-21 15:15  csuyangpeng  阅读(449)  评论(0编辑  收藏  举报

导航

//替换成自己路径的js文件