ssh changes the way python script behaves

Reply

Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

ssh changes the way python script behaves

 
0
  #1
Nov 14th, 2005
I wrote a python script that checks for new media on my windows box, if it is new it copys it over to my standalone freevo jukebox. Below is a small part of the script that does the actually copying
  1. source = "/mnt/samba/%s" %i
  2. destination = "/mnt/media/movies"
  3. print "copying %s to %s" %(i, destination)
  4. shutil.copy2(source, destination)

when I ssh into the freevo box then run the script it behaves like I think it shoud. first it runs the print function, then runs the shutil.copy2 function.

here is where it is behaving buggy. if I run the script directly using a command like this
  1. ssh root@192.168.1.103 /usr/local/bin/sambacopy.py

it does not print to the screen until after it has finished copying. I have found a solution of using sys.stdout.flush() directly after the print statment
  1. source = "/mnt/samba/%s" %i
  2. destination = "/mnt/media/movies"
  3. print "copying %s to %s" %(i, destination)
  4. sys.stdout.flush()
  5. shutil.copy2(source, destination)

why is the flush function needed when I run the script directly, but not if I ssh into a shell , then run the script
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,985
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 927
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite

Re: ssh changes the way python script behaves

 
0
  #2
Nov 15th, 2005
I have seen something similar when I mixed GUI with a few test prints. Python must internally prioritize, maybe has something to do with the internal memory manager.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC