s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
any_connection = False
while True:
try:
conn, addr = s.accept()
data = conn.recv(1024)
any_connection = True
# keep looking
if not data: continue
pid = os.fork()
if pid == 0:
server_process(data, conn)
except KeyboardInterrupt:
break
if any_connection:
print("Closing connection")
conn.close()
Run Code Online (Sandbox Code Playgroud)
我KeyboardInterrupt在用Python编写的无限运行的TCP服务器上捕获信号.但是,即使我知道它正在关闭连接,因为它打印Closing Connection,当我尝试重新运行服务器时,我得到:
OSError: [Errno 48] Address already in use
我不知道发生了什么,因为我知道我正在打电话conn.close().
并且运行killall python3没有解决它,我不断得到错误,除非我等待很长时间或更改端口.我也试图grep所有python3进程,但我什么都没得到.
我正在运行OS X Yosemite.
我知道我怎么能这样做,以便击中不插入标签,但空格.
但是,Emacs一直使用标签进行缩进,例如:
space space
space space space
tab tab space space
tab tab tab space space space
Run Code Online (Sandbox Code Playgroud)
这是一个混乱的混合,我如何配置它,以便它永远不会插入标签,什么?
我实际上发现了这个问题,但它说material.color并不存在.我需要知道如何更改我正在绘制的立方体的各个面的颜色:
var newCube = new THREE.Mesh(new three.CubeGeometry(size, size, size), new three.MeshNormalMaterial({ vertexColors: three.FaceColors }));
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的Webpack和Babel设置用于一个小型库.
之前,我有以下架构来生成库的ES5版本:
module.exports.lib = (function () {
/* private part of library here */
return {
... /* public part of library here */
}
})();
Run Code Online (Sandbox Code Playgroud)
一切都运行良好,我甚至有一些ES6功能,如我的库内的箭头功能,一切正常.但是,我决定将这种方法改为ES6类,这样:
export default class Library {
}
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试做的时候:
var library = new Library();
Run Code Online (Sandbox Code Playgroud)
我得到那个图书馆没有定义.即使只评估Library返回undefined.
所以我所做的是将使用该库的文件转换为ES6文件,import Library from 'libraryfile.js'然后再次运行.
但是,我真的很喜欢我的输出库仍然可以在普通的ES5中使用,<script>标签就像以前一样.这可能吗?
这是我的webpack配置文件:
module.exports = {
entry: {
pentagine: "./lib/pentagine.js",
demos: ["./demos/helicopter_game/PlayState.js"]
},
output: {
path: __dirname,
filename: "./build/[name].js",
libraryTarget: 'umd'
},
module: {
loaders: [
{
test: /.js$/,
loader: 'babel-loader', …Run Code Online (Sandbox Code Playgroud) 我在这里使用cabal安装包c2hs.但是,它需要快乐,所以我安装happy了cabal install happy.
之后,当我尝试安装时c2hs,language-c我package happy not found同时进行安装.
这是终端日志:
~> cabal install happy
Resolving dependencies...
[1 of 1] Compiling Main ( /tmp/happy-1.18.9-12936/happy-1.18.9/Setup.lhs, /tmp/happy-1.18.9-12936/happy-1.18.9/dist/setup/Main.o )
/tmp/happy-1.18.9-12936/happy-1.18.9/Setup.lhs:6:52:
Warning: In the use of `buildVerbose'
(imported from Distribution.Simple.Setup):
Deprecated: "Use buildVerbosity instead"
/tmp/happy-1.18.9-12936/happy-1.18.9/Setup.lhs:7:52:
Warning: In the use of `defaultUserHooks'
(imported from Distribution.Simple):
Deprecated: "Use simpleUserHooks or autoconfUserHooks, unless you need Cabal-1.2
compatibility in which case you must stick with defaultUserHooks"
/tmp/happy-1.18.9-12936/happy-1.18.9/Setup.lhs:12:26:
Warning: In …Run Code Online (Sandbox Code Playgroud) 我有两个类,这是其中一个的标题:
#ifndef WRAPPER_HPP
#define WRAPPER_HPP
#include <SDL/SDL.h>
using namespace std;
class Wrapper
{
private:
//SDL_Surface *screen;
public:
static SDL_Surface *screen;
static void set_screen(SDL_Surface *_screen);
static void set_pixel(int x, int y, Uint8 color);
static void clear_screen(int r, int g, int b);
static SDL_Surface* load_image(char path[500]);
static void draw_image(SDL_Surface *img, int x, int y, int width, int height);
static void draw_line(int x1, int y1, int x2, int y2, Uint8 color);
};
#endif
Run Code Online (Sandbox Code Playgroud)
我从另一个文件调用Wrapper :: set_screen(屏幕),我收到此错误:
In file included from /home/david/src/aships/src/Wrapper.cpp:6:0:
/home/david/src/aships/src/Wrapper.hpp: In …Run Code Online (Sandbox Code Playgroud) mov eax, 0x01
mov ecx, 0x02
div ecx ; Divide AX/CX, saves remainder in DX
cmp dx, 0
je OddNumber
int 80h
Run Code Online (Sandbox Code Playgroud)
当我尝试除1/2时,它返回"浮点异常",而不是标记OddNumber.我知道1/2是一个浮子,但我怎么能处理呢?谢谢.
GDB说"程序收到信号SIGFPE,算术异常." 顺便说说.
int array[] = {-1, 4, -2, 5, -5, 2, -20, 6};
Run Code Online (Sandbox Code Playgroud)
如果我有那个数组,我的Kadane算法实现找到最大的子数组工作:
int max_so_far = INT_MIN;
int max_ending_here = 0;
for (int i = 0; i < size; i++) {
max_ending_here = max(max_ending_here + array[i], 0);
max_so_far = max(max_ending_here, max_so_far);
}
printf("%d\n", max_so_far);
Run Code Online (Sandbox Code Playgroud)
但是,如果我有一个所有负数的数组:
int array[]= {-10, -10, -10};
Run Code Online (Sandbox Code Playgroud)
它不起作用,它应该返回-10,但我得到0.
我怎样才能让它对负数起作用?
谢谢!
from gi.repository import Gtk
#print Gtk.GTK_MAJOR_VERSION
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
Run Code Online (Sandbox Code Playgroud)
这是我的代码,我怎么知道正在使用哪个版本的Gtk.
谢谢!
#include <stdio.h>
#define LED 13
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop() {
int i;
char command[5];
for (i = 0; i < 4; i++) {
command[i] = Serial.read();
}
command[4] = '\0';
Serial.println(command);
if (strcmp(command, "AAAA") == 0) {
digitalWrite(LED, HIGH);
Serial.println("LED13 is ON");
} else if (strcmp(command, "BBBB") == 0) {
digitalWrite(LED, LOW);
Serial.println("LED13 is OFF");
}
}
Run Code Online (Sandbox Code Playgroud)
我试图用Arduino的Serial读取一个4个字符长的字符串,当它是AAAA时打开一个LED,当它是BBBB时关闭串口.
但是,当我输入"AAAA"时,它会显示"AAAÿ"并且沿途有很多"ÿ".
我认为我正在正确地阅读所有内容,但它运作得不好,对我做错了什么的想法?