これが起こっています。これを示して簡単な例
、以下を参照:
def fn():
print 'called'
return 1
target1 = fn()
target = fn
print target1
print target
これが印刷されます。
>>> called # Got called as soon as you called fn via fn()
>>> 1 # Assigned the return value of fn to target1
>>> <function fn at 0x12DA77F0> # Didn't get called, assigned the fn definition to target
私は以下Thread
S(編集での作業あなたの例を得た:いくつかを検討していた後、 Process
examplesのように、以下のコードと同じ構文で作業する必要があります(ちょうどインポートを変更し、の代わりにProcess
を使用してください)。)、何らかの理由で、たとえ例をコピーしても、Process
の印刷方法を取得できません。私のカスタムPythonのセットアップのために、しかし全くわからないかもしれません):。
from threading import Thread
import time
def foo(thread):
print(time.ctime())
time.sleep(10)
print(time.ctime())
def progress_bar(timer = 10):
digits = 4
delete = '\b' * 6
time_slot = float(timer)/100
for i in range(1, 101):
delete_bar = '\b' * 52
if i == 1:
bar = '|' + ' ' * 50 + '|'
else:
bar = '|' + '=' * (i/2 - 1) + '>' + ' ' * (50 - i/2) + '|'
print("{0}{1:{2}}{3}{4}".format(delete, str(i) + '%', digits, bar, delete_bar),)
time.sleep(time_slot)
print('')
def main():
t1 = Thread(target=foo, args=('this',)) # Notice, not foo('this') <- this executes foo('this') at definition
t1.start()
t2 = Thread(target=progress_bar) # Again, notice, no parens - target is just the function definition
t2.start()
t1.join()
t2.join()
これは
Tue Apr 05 15:09:34 2016
('1% | |',)
('2% |> |',)
('3% |> |',)
('4% |=> |',)
('5% |=> |',)
('6% |==> |',)
('7% |==> |',)
('8% |===> |',)
('9% |===> |',)
('10% |====> |',)
('11% |====> |',)
('12% |=====> |',)
('13% |=====> |',)
('14% |======> |',)
('15% |======> |',)
('16% |=======> |',)
('17% |=======> |',)
('18% |========> |',)
('19% |========> |',)
('20% |=========> |',)
('21% |=========> |',)
('22% |==========> |',)
('23% |==========> |',)
('24% |===========> |',)
('25% |===========> |',)
('26% |============> |',)
('27% |============> |',)
('28% |=============> |',)
('29% |=============> |',)
('30% |==============> |',)
('31% |==============> |',)
('32% |===============> |',)
('33% |===============> |',)
('34% |================> |',)
('35% |================> |',)
('36% |=================> |',)
('37% |=================> |',)
('38% |==================> |',)
('39% |==================> |',)
('40% |===================> |',)
('41% |===================> |',)
('42% |====================> |',)
('43% |====================> |',)
('44% |=====================> |',)
('45% |=====================> |',)
('46% |======================> |',)
('47% |======================> |',)
('48% |=======================> |',)
('49% |=======================> |',)
('50% |========================> |',)
('51% |========================> |',)
('52% |=========================> |',)
('53% |=========================> |',)
('54% |==========================> |',)
('55% |==========================> |',)
('56% |===========================> |',)
('57% |===========================> |',)
('58% |============================> |',)
('59% |============================> |',)
('60% |=============================> |',)
('61% |=============================> |',)
('62% |==============================> |',)
('63% |==============================> |',)
('64% |===============================> |',)
('65% |===============================> |',)
('66% |================================> |',)
('67% |================================> |',)
('68% |=================================> |',)
('69% |=================================> |',)
('70% |==================================> |',)
('71% |==================================> |',)
('72% |===================================> |',)
('73% |===================================> |',)
('74% |====================================> |',)
('75% |====================================> |',)
('76% |=====================================> |',)
('77% |=====================================> |',)
('78% |======================================> |',)
('79% |======================================> |',)
('80% |=======================================> |',)
('81% |=======================================> |',)
('82% |========================================> |',)
('83% |========================================> |',)
('84% |=========================================> |',)
('85% |=========================================> |',)
('86% |==========================================> |',)
('87% |==========================================> |',)
('88% |===========================================> |',)
('89% |===========================================> |',)
('90% |============================================> |',)
('91% |============================================> |',)
('92% |=============================================> |',)
('93% |=============================================> |',)
('94% |==============================================> |',)
('95% |==============================================> |',)
('96% |===============================================> |',)
('97% |===============================================> |',)
('98% |================================================> |',)
Tue Apr 05 15:09:44 2016
('99% |================================================> |',)
('100%|=================================================>|',)
これは私が欲しいものです!どうもありがとうございました! – yc2986
あなたは大歓迎です! – RiTu