我试着守护一些代码,但是我遇到了麻烦.
如果我用tklogger()调用代码,它运行得很好.但是,如果我在守护进程上下文中调用它,我会得到以下跟踪:
Traceback (most recent call last):
File "./tklogger.py", line 103, in <module>
tklogger()
File "./tklogger.py", line 41, in tklogger
conn, addr = s.accept()
File "/usr/lib/python2.6/socket.py", line 195, in accept
sock, addr = self._sock.accept()
socket.error: [Errno 9] Bad file descriptor
close failed in file object destructor:
IOError: [Errno 9] Bad file descriptor
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
#!/usr/bin/python
# tklogger, a TK10X GPS tracking device logger
import socket
import time
import daemon
HOST = '' # Bind to all interfaces
PORT = 9000 # …Run Code Online (Sandbox Code Playgroud) 我在JS中遇到了一些问题,我刚刚接受了.
我已经定义了一个对象,并在其中进行.getJSON()调用,但我似乎无法正确引用调用对象的属性:
// Vehicle object
function vehicle(id) {
this.id = id;
var that = this;
// Fetch some JSON
$.getJSON("json.php?act=vehicleInfo&id=" + this.id, function (json) {
that.vehicleInfo = json
that.icon = L.AwesomeMarkers.icon({ icon: that.vehicleInfo.icon, color: that.vehicleInfo.colour });
that.polyline = new L.Polyline([[that.vehicleInfo.latitude, that.vehicleInfo.longitude]]);
that.marker = L.marker([that.vehicleInfo.latitude, that.vehicleInfo.longitude], {icon: that.icon});
that.marker.bindPopup("Test point");
that.marker.addTo(map);
that.polyline.addTo(map);
});
}
// Vehicle move method
vehicle.prototype.move = function(latlng){
this.marker.setLatLng(latlng);
this.polyline.addLatLng(latlng);
}
Run Code Online (Sandbox Code Playgroud)
当我调用.move()时,this.marker未定义.我在哪里错了?