2016-03-24 12 views
0

Aşağıdaki python komut dosyasını kullanıyorum ve bir ana bilgisayarda çalıştırdığımda başka bir makinede yaklaşık 65 değerde sıkıştığım için garip bir sorun yaşıyorum. bundan sonra donuyor. Ayrıca traktörü de dahil ettim. Her iki makine de aynı ağ olan Centos'dur. peşinxenserver'den veri toplarken python ile garip bir sorun

open("/usr/lib64/python2.7/httplib.py", O_RDONLY) = 4 
fstat(4, {st_mode=S_IFREG|0644, st_size=48234, ...}) = 0 
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa108b7e000 
read(4, "r\"\"\"HTTP/1.1 client library\n\n<in"..., 4096) = 4096 
read(4, "THENTICATION_REQUIRED = 407\nREQU"..., 4096) = 4096 
read(4, "nread'):\n   unread = se"..., 4096) = 4096 
write(2, " ", 4)      = 4 
write(2, "line = self.fp.readline(_MAXLINE"..., 38) = 38 
close(4)        = 0 
munmap(0x7fa108b7e000, 4096)   = 0 
write(2, " File \"/usr/lib64/python2.7/soc"..., 63) = 63 
open("/usr/lib64/python2.7/socket.py", O_RDONLY) = 4 
fstat(4, {st_mode=S_IFREG|0644, st_size=20512, ...}) = 0 
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa108b7e000 
read(4, "# Wrapper module for _socket, pr"..., 4096) = 4096 
read(4, "oo long.\"\n errorTab[10064] = "..., 4096) = 4096 
read(4, "sed\" is a property, see below\n "..., 4096) = 4096 
read(4, "  try:\n     "..., 4096) = 4096 
read(4, "   nl = data.find('\\n')"..., 4096) = 4096 
write(2, " ", 4)      = 4 
write(2, "data = self._sock.recv(self._rbu"..., 39) = 39 
close(4)        = 0 
munmap(0x7fa108b7e000, 4096)   = 0 
write(2, "KeyboardInterrupt", 17)  = 17 
write(2, "\n", 1)      = 1 
rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7fa10838d130}, {0x7fa1086ab6a0, [], SA_RESTORER, 0x7fa10838d130}, 8) = 0 
close(3)        = 0 
close(8)        = 0 
exit_group(1)       = ? 
+++ exited with 1 +++ 

Teşekkür: Burada

#!/usr/bin/python 

import XenAPI 
import string, time, os, ConfigParser, sys, re 
def errorAndExit(message): 
    print "ERROR: Something went wrong! -", message 
    exit(1) 

def grabXenData(session, config): 

    try: 
    vms = session.xenapi.VM.get_all() 
    except: 
    errorAndExit("Couldn't retrieve all VM's") 
    for vm in vms: 
    record = session.xenapi.VM.get_record(vm) 
    if (record["power_state"] == "Running") and not (record["is_control_domain"]): 
     if (record["actions_after_crash"] != "destroy"): 
      print record["name_label"] 


if __name__ == '__main__': 

    CONFIG_FILE = (os.getcwd() + "/config.txt") 
    config = ConfigParser.ConfigParser() 
    config.read([CONFIG_FILE]) 

    wait = config.get('XENAPI', 'WAIT') 

    # time.sleep expects a float, convert the var here. 
    wait = float(wait) 

    url = "http://" + config.get('XENAPI', 'HOSTNAME') 
    print url 
    username = config.get('XENAPI', 'USERNAME') 
    password = config.get('XENAPI', 'PASSWORD') 
    while True: 
    session = XenAPI.Session(url) 
    print session 
    try: 
     session.xenapi.login_with_password(username, password) 
    except: 
     errorAndExit("Could not connect to host, CHECK: URL, username, password") 

    grabXenData(session, config) 
    session.xenapi.session.logout() 
    exit() 

yığın izidir. Daha fazla bilgi lütfen bize bildirin.

cevap

0

Neden bilmiyorum, ancak istisna dışında sys.exit kullanmalısınız.

open("/usr/lib64/python2.7/httplib.py", O_RDONLY) = 4 
fstat(4, {st_mode=S_IFREG|0644, st_size=48234, ...}) = 0 
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa108b7e000 
read(4, "r\"\"\"HTTP/1.1 client library\n\n<in"..., 4096) = 4096 
read(4, "THENTICATION_REQUIRED = 407\nREQU"..., 4096) = 4096 

sana "hakkı" piton bağları kullanıyorsanız, denemek gerektiğini düşünüyorum:

#!/usr/bin/python 

import XenAPI 
import string, time, os, ConfigParser, sys, re 
def errorAndExit(message): 
    print "ERROR: Something went wrong! -", message 
    sys.exit(1) 

def grabXenData(session, config): 
    vms = [] 
    try: 
    vms = session.xenapi.VM.get_all() 
    except Exception: 
    errorAndExit("Couldn't retrieve all VM's") 
    for vm in vms: 
    record = session.xenapi.VM.get_record(vm) 
    if (record["power_state"] == "Running") and not (record["is_control_domain"]): 
     if (record["actions_after_crash"] != "destroy"): 
      print record["name_label"] 


if __name__ == '__main__': 

    CONFIG_FILE = (os.getcwd() + "/config.txt") 
    config = ConfigParser.ConfigParser() 
    config.read([CONFIG_FILE]) 

    wait = config.get('XENAPI', 'WAIT') 

    # time.sleep expects a float, convert the var here. 
    wait = float(wait) 

    url = "http://" + config.get('XENAPI', 'HOSTNAME') 
    print url 
    username = config.get('XENAPI', 'USERNAME') 
    password = config.get('XENAPI', 'PASSWORD') 
    while True: 
    session = XenAPI.Session(url) 
    print session 
    try: 
     session.xenapi.login_with_password(username, password) 
    except Exception: 
     errorAndExit("Could not connect to host, CHECK: URL, username, password") 

    grabXenData(session, config) 
    session.xenapi.session.logout() 
    sys.exit(0) 

bir hatayla ATHENTICATION_REQUIRED aldık.

İlgili konular