1
我正尝试使用cygwin来运行我的Python代码。该脚本应该启动一个线程并对其进行处理。但它以某种方式不起作用。作为一个最小的例子,我使用这里的代码'http://www.saltycrane.com/blog/2008/09/simplistic-python-thread-example/'。 正如你可以在下面的日志中看到的,Thread.start()
在cygwin中结束Pyhton交互式输入,没有任何消息。 相反,在另一台机器上,程序按预期运行。我期待cygwin问题,但在cygwin上重新安装Python软件包并没有帮助。Python线程无法在cygwin上运行
想法?
$ python
Python 2.7.12 (default, Oct 10 2016, 12:56:26)
[GCC 5.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
def myfunc(i):
print "sleeping 5 sec from thread %d" % i
time.sleep(5)
print "finished sleeping from thread %d" % i
for i in range(10):
t = Thread(target=myfunc, args=(i,))
t.start()
>>> from threading import Thread
>>>
>>> def myfunc(i):
... print "sleeping 5 sec from thread %d" % i
... time.sleep(5)
... print "finished sleeping from thread %d" % i
...
>>> for i in range(10):
... t = Thread(target=myfunc, args=(i,))
... t.start()
...
[email protected]~
$
好吧,我的错,我没有说清楚,但它是一个cygwin问题!我发布的程序也适用于另一台机器。 - >调整问题... – Mario
我的版本在cygwin python上运行。你测试过了吗?缺少“导入时间,线程”和“threading.Thread”导致执行错误。 – matzeri
运行它我得到了一个语法错误,因为'%i'\ n''。解决这个问题后,脚本运行时没有任何输出... – Mario