0

「.py」ファイルにpythonスクリプトがあり、基本的に次のようなもので構成されています。

#import time and tcmodule.py module
import time
import tcmodule as tc

# Set Inputs (step 1):
tc.SetInput1(0)
tc.SetInput2(0)
tc.SetInput3(0)
time.sleep(0.250)
print(time.time())

# Set Inputs (step 2):
tc.SetInput1(3)
tc.SetInput2(6)
tc.SetInput3(12)
time.sleep(0.250)
print(time.time())

#the code continues the same way...

これら 4 つの命令を含む「Set Inputs」ブロックは約 900 回繰り返されるため、ファイルは非常に長くなりますが、簡単に理解できます。いくつかの変数にいくつかの値を与え、250ms 待ちます。

問題は、プログラムの実行中に pythonwin が突然スクリプトの読み取りを停止することです (突然時刻の出力が停止するためです)。なぜそれが起こるのかわかりません。最も奇妙なことは、毎回異なる場所で停止することです。そのため、コードは問題ないと思います。コードの何が問題なのか誰か知っていますか?

4

3 に答える 3

0

これでメモリプロファイラーを使用することをお勧めします。メモリが不足している可能性があります。または、入力が tc.SetInput が期待するものと異なる可能性があります。

#import time and tcmodule.py module
import time
import tcmodule as tc
from memory_profiler import profile

@profile
def my_func():
    tc.SetInput1(input1)
    tc.SetInput2(input2)
    tc.SetInput3(input3)
    time.sleep(0250)
    print(time.time())
def parseline():
   #take out the "pass" and return the 3 input values
   pass

with somefile.txt as txtfile:
   for line in file:
      try:
          input1,input2,input3=parseline(line)
          myfunc(input1,input2,input3)
      except Exception:
          #add error handling here and change the Exception.
于 2013-11-13T18:30:52.620 に答える
0

頻繁に繰り返す必要がないように、プログラムを再構築する必要があります。呼び出しのパラメーターSetInputが毎回異なっていても、多くのことを節約できます。

import time
import tcmodule as tc

inputs = [
    (0, 0, 0),
    (3, 6, 12),
    # more values here
]

for a, b, c in inputs:
    tc.SetInput1(a)
    tc.SetInput2(b)
    tc.SetInput3(c)
    time.sleep(0.250)
    print(time.time())

基本的に、すべての入力パラメーターを大きなリストに保存し、それを一度指定する必要があります。次に、値をループして、それらの関数を一度呼び出すブロックを記述します。これにより、ファイルの深い場所での呼び出しで入力エラーが発生することも防止されます。したがって、これで問題はすでに解決している可能性があります。

于 2013-11-13T18:23:17.460 に答える
0

おそらく、900回の繰り返しのどこかでタイプミスの問題があるでしょう。このようなことをお勧めします。これにより、デバッグがはるかに簡単になります。

# create a list of lists
# each sublist will contain the three values that go with each SetInput function
# add as many sublists as necessary 
inputs = [[0, 0, 0], [3, 6, 12]]

for inp in inputs:
    print "step", inp
    tc.SetInput1(inp[0])
    tc.SetInput2(inp[1])
    tc.SetInput3(inp[2])
    time.sleep(0.250)
    print(time.time())
于 2013-11-13T18:23:41.813 に答える