Python 2.7 Python线程没有';不要在cygwin身上跑步

Python 2.7 Python线程没有';不要在cygwin身上跑步,python-2.7,cygwin,Python 2.7,Cygwin,我正在尝试使用cygwin来运行我的Python代码。脚本应该启动一个线程并处理它。但不知怎么的,它不起作用。作为一个简单的示例,我使用了这里的代码“”。 正如您在下面的日志中所看到的,Thread.start()在cygwin中结束Pyhton交互输入,而不显示任何消息。 相反,在另一台机器上,程序按预期运行。我预计cygwin会出现问题,但在cygwin上重新安装Python包并没有帮助 想法 $ python Python 2.7.12 (default, Oct 10 2016, 12:

我正在尝试使用cygwin来运行我的Python代码。脚本应该启动一个线程并处理它。但不知怎么的,它不起作用。作为一个简单的示例,我使用了这里的代码“”。 正如您在下面的日志中所看到的,
Thread.start()
在cygwin中结束Pyhton交互输入,而不显示任何消息。 相反,在另一台机器上,程序按预期运行。我预计cygwin会出现问题,但在cygwin上重新安装Python包并没有帮助

想法

$ 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()
...

xyz@mypc~
$
以这种方式重写
cat prova python.py

#!/usr/byn/python
import time,threading

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 = threading.Thread(target=myfunc, args=(i,))
    t.start()
工作正常,但第二阶段的输出可能会在线程之间重叠

 $ python prova-python.py
sleeping 5 sec from thread 0
sleeping 5 sec from thread 1
sleeping 5 sec from thread 2
sleeping 5 sec from thread 3
sleeping 5 sec from thread 4
sleeping 5 sec from thread 5
sleeping 5 sec from thread 6
sleeping 5 sec from thread 7
sleeping 5 sec from thread 8
sleeping 5 sec from thread 9
finished sleeping from thread 0
finished sleeping from thread 2
finished sleeping from thread 1
finished sleeping from thread 3
finished sleeping from thread 4
finished sleeping from thread 5
finished sleeping from thread 6
finished sleeping from thread 9finished sleeping from thread 8finished sleeping from thread 7
以这种方式重写
cat prova python.py

#!/usr/byn/python
import time,threading

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 = threading.Thread(target=myfunc, args=(i,))
    t.start()
工作正常,但第二阶段的输出可能会在线程之间重叠

 $ python prova-python.py
sleeping 5 sec from thread 0
sleeping 5 sec from thread 1
sleeping 5 sec from thread 2
sleeping 5 sec from thread 3
sleeping 5 sec from thread 4
sleeping 5 sec from thread 5
sleeping 5 sec from thread 6
sleeping 5 sec from thread 7
sleeping 5 sec from thread 8
sleeping 5 sec from thread 9
finished sleeping from thread 0
finished sleeping from thread 2
finished sleeping from thread 1
finished sleeping from thread 3
finished sleeping from thread 4
finished sleeping from thread 5
finished sleeping from thread 6
finished sleeping from thread 9finished sleeping from thread 8finished sleeping from thread 7

好吧,我的错,我没有说清楚,但这是一个cygwin问题!我发布的程序也可以在另一台机器上运行。-->问题调整…我的版本在cygwin python上工作。你测试过了吗?缺少
导入时间、线程
线程。线程
导致执行错误。运行它时,由于
%I'\n'
而出现语法错误。解决此问题后,脚本运行时没有任何输出…没有输出?比你有一个系统问题。其他python程序是否正常工作?好吧,是我的错,我没有说清楚,但这是cygwin的问题!我发布的程序也可以在另一台机器上运行。-->问题调整…我的版本在cygwin python上工作。你测试过了吗?缺少
导入时间、线程
线程。线程
导致执行错误。运行它时,由于
%I'\n'
而出现语法错误。解决此问题后,脚本运行时没有任何输出…没有输出?比你有一个系统问题。其他python程序是否正常工作?