当我在Intellij上运行以下代码并输入1000000000000时,该过程每隔800万个循环保持一个时刻.
为什么会这样?为什么直到最后都没有顺利流动?
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Please type a number");
long n = in.nextLong();
System.out.println("Thanks.");
long count = 0;
for (long i=0; i<=n; i++) {
if ((n+i) == (n^i)) {
count++;
if (count % 1000000 == 0)
System.out.println(count);
}
}
System.out.println(count);
}
}
Run Code Online (Sandbox Code Playgroud) 在Python程序中,我需要获得主机上所有磁盘的累计读/写速度.我这样做是subprocess.check_output()为了调用以下Linux shell命令:
$ sudo hdparm -t /dev/sda
Run Code Online (Sandbox Code Playgroud)
这给出了结果:
/dev/sda:
Timing buffered disk reads: 1488 MB in 3.00 seconds = 495.55 MB/sec
Run Code Online (Sandbox Code Playgroud)
然后我可以解析495.55.好的,到目前为止一切顺利.
但是在我的手册页上hdparm找到了这个-t标志的解释,基本上说在执行测量时没有其他进程应该同时读/写磁盘:
执行设备读取的时间以进行基准测试和比较.为了获得有意义的结果,此操作应在其他非活动系统(没有其他活动进程)上重复2-3次,并且至少有几兆字节的可用内存.这将显示通过缓冲区高速缓存读取磁盘的速度,而无需事先缓存数据.此测量表明驱动器在Linux下可以维持顺序数据读取的速度,而不会产生任何文件系统开销.为确保准确测量,在使用BLKFLSBUF ioctl处理-t期间刷新缓冲区高速缓存.
问题是:
如何在执行测量时确保没有其他进程同时访问磁盘?
当我在我的Ubuntu终端中运行时:
sudo dd if=/dev/sda of=~/file bs=8k count=200k; rm -f ~/file
Run Code Online (Sandbox Code Playgroud)
它工作正常.
如果我通过Pythons运行它subprocess.Popen():
output, err = subprocess.Popen(['sudo', 'dd', 'if=/dev/' + disk, 'of=~/disk_benchmark_file', 'bs=8k', 'count=200k'], stderr=subprocess.PIPE).communicate()
print err
Run Code Online (Sandbox Code Playgroud)
它不起作用.我得到的错误是:
dd:无法打开'〜/ disk_benchmark_file':没有这样的文件或目录
如果我在改变Popen()通话的波浪~来/home/user,然后它的作品!
为什么会那样?对我来说更重要的是:我怎样才能让它发挥作用? 我不知道生产中的用户名是什么.
有什么问题?
我在PyCharm(版本2016.1.4)中使用远程解释器(而不是Debug Server!)进行了远程调试,如下所述:jetbrains网站。
当我在“调试”模式下运行时,程序会在断点处按其应有的方式停止。但是,在“变量”窗口中不会显示变量。相反,我得到以下错误:
无法显示框架变量
我想这是同样的问题:链接
我尝试了什么?
我发现此链接提供了可能的解决方案,但对我而言不起作用。基于此解决方案,我对helpers/pydev/_pydevd_bundle/pydevd_constants.py文件进行了如下修改:
从:
try:
SUPPORT_GEVENT = os.getenv('GEVENT_SUPPORT', 'False') == 'True'
except:
# Jython 2.1 doesn't accept that construct
SUPPORT_GEVENT = False
# At the moment gevent supports Python >= 2.6 and Python >= 3.3
USE_LIB_COPY = SUPPORT_GEVENT and \
((not IS_PY3K and sys.version_info[1] >= 6) or
(IS_PY3K and sys.version_info[1] >= 3))
Run Code Online (Sandbox Code Playgroud)
至:
try:
SUPPORT_GEVENT = os.getenv('GEVENT_SUPPORT', 'False') == 'True'
try:
import gevent
SUPPORT_GEVENT = True
except:
SUPPORT_GEVENT …Run Code Online (Sandbox Code Playgroud) python ×2
bash ×1
dd ×1
gevent ×1
java ×1
linux ×1
performance ×1
popen ×1
pycharm ×1
subprocess ×1