我在某处读到KeyboardInterrupt异常只在Python的主线程中引发.我还读到在子线程执行时主线程被阻塞.那么,这是否意味着CTRL+ C永远不会到达子线程.我尝试了以下代码:
def main():
try:
thread = threading.Thread(target=f)
thread.start() # thread is totally blocking (e.g., while True)
thread.join()
except KeyboardInterrupt:
print "Ctrl+C pressed..."
sys.exit(1)
def f():
while True:
pass # do the actual work
Run Code Online (Sandbox Code Playgroud)
在这种情况下,CTRL+ C对执行没有影响.它就像是无法收听信号.我理解这是错误的方式吗?有没有其他方法可以使用CTRL+ 杀死线程C?
可能重复:
在C++中查找对象的类型
您好,
我很抱歉,如果它是重复但我无法在这里找到我的问题的答案.
假设我们在c ++中有以下类结构:
class CPolygon {
protected:
int width, height;
public:
void set_values (int a, int b)
{ width=a; height=b; }
};
class CRectangle: public CPolygon {
public:
int area ()
{ return (width * height); }
};
Run Code Online (Sandbox Code Playgroud)
现在我有一个指向CPolygon对象的指针.如何检查它是否实际上是指向类CRectangle对象的指针?
我安装了64位RHEL.我有关于系统的ant.jar的以下问题.
我认为移位运算符会移动整数的内存或应用它的字符,但以下代码的输出对我来说是一个惊喜.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(void) {
uint64_t number = 33550336;
unsigned char *p = (unsigned char *)&number;
size_t i;
for (i=0; i < sizeof number; ++i)
printf("%02x ", p[i]);
printf("\n");
//shift operation
number = number<<4;
p = (unsigned char *)&number;
for (i=0; i < sizeof number; ++i)
printf("%02x ", p[i]);
printf("\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它运行的系统是little endian并产生以下输出:
00 f0 ff 01 00 00 00 00
00 00 ff 1f 00 00 00 00
Run Code Online (Sandbox Code Playgroud)
有人可以提供一些参考变速操作员的详细工作吗?