2013-09-28 2 views
0

안녕하세요 지금은 작은 문제가 있지만 그럼에도 불구하고 문제가 있습니다. 파이썬 스크립트는 gksudo를 통해 실행될 때 순서대로 실행되지 않는 것 같습니다. 첫 번째 if 블록의 시스템 명령은 이전에 실행됩니다.gksudo 및 python 스크립트

print ("Removing Partial, Unneeded, And Obsolete Packages..."); 

해당 줄.

#!/usr/bin/env python 

import os; 

F1 = open('/tmp/F1.txt', 'r').read(); 
F2 = open('/tmp/F2.txt', 'r').read(); 
F3 = open('/tmp/F3.txt', 'r').read(); 
F4 = open('/tmp/F4.txt', 'r').read(); 
F5 = open('/tmp/F5.txt', 'r').read(); 
os.system("rm /tmp/F1.txt"); 
os.system("rm /tmp/F2.txt"); 
os.system("rm /tmp/F3.txt"); 
os.system("rm /tmp/F4.txt"); 
os.system("rm /tmp/F5.txt"); 


if F1=="1": 
    print ("Removing Partial, Unneeded, And Obsolete Packages..."); 
    os.system ("sudo apt-get clean -y -f"); 
    os.system ("sudo apt-get autoremove -y -f"); 
    os.system ("sudo apt-get autoclean -y -f"); 
    open('/tmp/Point.txt', 'w').write("2"); 
    print ("...Done"); 

if F2=="1": 
    print ("Clearing Temporary Files..."); 
    os.system ("sudo rm -rf /tmp/*"); 
    open('/tmp/Point.txt', 'w').write("3"); 
    print ("...Done"); 

if F3=="1": 
    print ("Clearing Unused Thumbnails..."); 
    os.system ("rm -f ~/.thumbnails/normal/*"); 
    open('/tmp/Point.txt', 'w').write("4"); 
    print ("...Done"); 

if F4=="1": 
    print ("Clearing Downloads Folder..."); 
    os.system ("rm -r ~/Downloads/*"); 
    open('/tmp/Point.txt', 'w').write("5"); 
    print ("...Done"); 

if F5=="1": 
    print ("Emptying Trash..."); 
    os.system ("rm -rf ~/.local/share/Trash/*"); 
    open('/tmp/Point.txt', 'w').write("6"); 
    print ("...Done"); 

print (""); 
os.system("rm /tmp/Point.txt"); 
print ("Cleanup Complete."); 

이 A.S.A.P., 브룩스 레디가 도와주세요 : 여기

내 스크립트의 나머지 부분입니다.

답변

1

이것은 단순한 추측이지만,보고있는 내용은 I/O buffering입니다. 이것이 Python 3.3 이후 버전 인 경우 print(message, flush=True)을 시도하십시오. 파이썬 2에서는 sys.stdout.flush()으로 전화해야하지만 stdout이 터미널이 아니라고 판단 될 때만 발생합니다. 예를 들어 cron으로 실행되거나 다른 프로그램으로 파이프되는 경우. 이 문제를 설명하기 위해 스크립트를 실행합니다

import time, sys 

print "hello there" 
#sys.stdout.flush() 
time.sleep(2) 
print "bye" 

실행이 python script를 사용하는 경우, 그것은 잘 작동하지만, 2 초 경과 할 때까지 python script | dd bs=1 아무것도 모두 인쇄 선이 나타나는 시점에서 표시되지 않습니다 같은 경우는 실행됩니다. 플러시가 발생하도록 #을 제거하면이 문제가 해결됩니다.

이 I/O 버퍼링의 이유는 많은 수의 작은 인쇄물을 수집하여 외부 I/O에 대한 호출 횟수를 줄이기 때문입니다. 눈에 띄는 차이는 거의 없지만, 예를 들어 마모 된 메모리 또는 고정 블록 크기의 I/O 장치와 같이 결국에는 문제가 될 수 있습니다. 이 차이를 표시하는 데 사용한 dd 명령은 구성 가능한 매개 변수 (이 경우 1 바이트)로 버퍼링합니다.

덧붙여서 스크립트의 모든 세미콜론은 필요하지 않습니다.

+0

도움이 될 것이라고 생각했지만, 불행히도 내 문제는 지속됩니다. 어떤 아이디어? – thelostlambda