在一个多线程的跨平台python3.3应用程序上工作我遇到了一些我没想到的奇怪行为,并且我不确定是否可以预期.问题出在Windows 8上,input()在一个线程中调用该方法会阻塞其他线程,直到完成为止.我在三台Linux,两台Windows 7和一台Windows 8计算机上测试了下面的示例脚本,这种行为仅在Windows 8计算机上观察到.这是Windows 8的预期行为吗?
test.py:
import subprocess, threading, time
def ui():
i = input("-->")
print(i)
def loop():
i = 0
f = 'sky.{}'.format(i)
p = subprocess.Popen(['python', 'copy.py', 'sky1', f])
t = time.time()
while time.time() < t+15:
if p.poll() != None:
print(i)
time.sleep(3)
i+=1
f = 'sky.{}'.format(i)
p = subprocess.Popen(['python', 'copy.py', 'sky1', f])
p.terminate()
p.wait()
def start():
t1 = threading.Thread(target=ui)
t2 = threading.Thread(target=loop)
t1.start()
t2.start()
return t2
t2 = start()
t2.join()
print('done')
Run Code Online (Sandbox Code Playgroud)
copy.py:
import shutil
import sys …Run Code Online (Sandbox Code Playgroud) 当我这样做(0x7fffffff | 0x8000000)时,我得到0xffffffffffffffff而不是预期的0xffffffff.我错过了什么?
一些示例代码和输出来说明我的问题.
码:
#include <iostream>
using namespace std;
int main()
{
unsigned long long val = 0;
for (int i = 0; i < 64; i++) {
val |= 0x1 << i;
cout << i << ": " << std::hex << val << std::dec << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
0: 1 1: 3 2: 7 3: f 4: 1f 5: 3f 6: 7f 7: ff 8: 1ff 9: 3ff 10: 7ff 11: fff 12: 1fff 13: …