在Python中,如何检查是否sys.stdin有数据?
我发现不仅os.isatty(0)可以检查stdin是否连接到TTY设备,还可以检查是否有可用的数据.
但如果有人使用像
sys.stdin = cStringIO.StringIO("ddd")
Run Code Online (Sandbox Code Playgroud)
在使用之后os.isatty(0),它仍然返回True.我需要做些什么来检查stdin是否有数据?
我在Arch Linux上运行i7-5930k 6核CPU和64GB DDR4 RAM,我正在使用IntelliJ IDEA 14.
几天前,IDEA对我来说工作得很好,但是有一天,突然之间,在"索引"阶段开始项目后,它开始挂起了.我没有更新IDEA,也没有改变我的项目.IDE的UI在打开项目后挂起,只需要一小段"索引"完成的进度条.每隔5-10分钟左右解冻,进度条向前爬一点,然后IDE再次冻结几分钟.这种情况反复发生在15分钟到1小时之间,直到它最终完成索引,此时它再挂5-10分钟,在最终解锁并允许我开发之前.
虽然这种情况正在发生,但我的系统相当反应迟钝 - Firefox标签需要很长时间才能切换,而滚动它们是滞后的.打开一个新的终端窗口需要很长时间.通常切换窗口需要一段时间.在htop,我的一个CPU内核以100%加载,而其余的CPU负载正常,并且使用了大约6GB的RAM(当系统空闲时相当正常的负载.)
我尝试过的事情没有帮助:
这个问题确实伤害了我的工作流程,如果有人对此有任何解决方案,我会非常感激.
我一直在谷歌搜索,似乎无法找到解决方案.我在这做错了什么?我的问题在标题中.这是我得到的例外:
java.lang.IllegalStateException
at java.util.ArrayList$Itr.remove(Unknown Source)
at me.herp.derp.client.Config.updateItem(Config.java:24)
at me.herp.derp.client.Commands.parseCommand(Commands.java:23)
at me.herp.derp.client.ChatCommands.handleChatcommand(ChatCommands.java:29)
at net.minecraft.src.EntityClientPlayerMP.sendChatMessage(EntityClientPlayerMP.java:171)
at net.minecraft.src.GuiChat.keyTyped(GuiChat.java:104)
at net.minecraft.src.GuiScreen.handleKeyboardInput(GuiScreen.java:227)
at net.minecraft.src.GuiScreen.handleInput(GuiScreen.java:176)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1494)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:843)
at net.minecraft.client.Minecraft.run(Minecraft.java:768)
at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
public static void updateItem(String item, String value)
{
if (!hasValue(item))
{
addItem(item, value);
return;
}
for (ConfigItem c : configItems)
{
if (c.ITEM.equals(item))
{
configItems.iterator().remove();
break;
}
}
ConfigFile.saveConfig();
}
Run Code Online (Sandbox Code Playgroud) 我目前在使用 Xlib 时遇到问题,每当我调用XKeysymToKeycode()并传入一个大写字母时KeySym,它都会返回一个小写字母KeyCode。就此而言,Google 似乎并没有真正回答这个问题,也没有太多关于我正在使用的功能的文档。
这是我正在使用的代码:
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>
int main(void) {
Display *display;
char *ptr;
char c[2] = {0, 0};
KeySym ksym;
KeyCode kcode;
display = XOpenDisplay(0);
ptr = "Test";
while (*ptr) {
c[0] = *ptr;
ksym = XStringToKeysym(c);
printf("Before XKeysymToKeycode(): %s\n", XKeysymToString(ksym));
kcode = XKeysymToKeycode(display, ksym);
printf("Key code after XKeysymToKeycode(): %s\n", XKeysymToString(XKeycodeToKeysym(display, kcode, 0)));
ptr++;
}
XCloseDisplay(display);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它可以编译为gcc …
出于某种原因,这段代码是segfaulting,原因我无法找到.
char *read_line(FILE *fp)
{
char *out;
int counter = 0;
char c = getc(fp);
while (c != '\n' && c != EOF)
{
*(out + counter) = c;
counter++;
c = getc(fp);
}
if (c == EOF || feof(fp))
{
return NULL;
}
*(out + counter) = '\0';
return out;
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过运行它gdb,并告诉我段错误是在*(out + counter) = c;.我无法弄清楚我做错了什么,还有其他人吗?
在我为我的网站进行负载测试而编写的HTTP flooder中使用libCURL时,我遇到了段错误.
以下是相关代码:https://gist.github.com/AppleDash/a26e0ce0b138cd9eacd2(这里要粘贴一点点.)
这是一个链接到它是segfaulting的行:https://gist.github.com/AppleDash/a26e0ce0b138cd9eacd2#file-httpflood-improved-c-L57
这是段错误的回溯:
#0 0x00007ffff760d65b in fwrite () from /usr/lib/libc.so.6
#1 0x00007ffff79656d8 in ?? () from /usr/lib/libcurl.so.4
#2 0x00007ffff797a76b in ?? () from /usr/lib/libcurl.so.4
#3 0x00007ffff7984349 in ?? () from /usr/lib/libcurl.so.4
#4 0x00007ffff7984b11 in curl_multi_perform () from /usr/lib/libcurl.so.4
#5 0x00007ffff797b977 in curl_easy_perform () from /usr/lib/libcurl.so.4
#6 0x0000000000400f42 in flood (structPointer=0x7fffffffe060) at httpflood.c:57
#7 0x00007ffff7bc5124 in start_thread () from /usr/lib/libpthread.so.0
#8 0x00007ffff768b4bd in clone () from /usr/lib/libc.so.6
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这个电话会导致段错误.有任何想法吗?
我知道你的意思是只提供相关代码的一小部分样本,但在这里我提供了整个事情,因为我觉得这里需要上下文.(事实上,它是从许多线程运行的.)