Synchronous shutil.copyfile()

Sick Monkey sickcodemonkey at gmail.com
Tue Jan 30 16:18:40 CET 2007


First off, I am just learning Python, so if there is a more efficient way to
do this, then I am all ears....   (NOTE:  The code below is something that I
was messing with to learn threads...  So some functionality is not
applicable for your needs..I just wanted to show you a demonstration)
One way that you could get around this, is to use threads.   You can lock
your thread and when the lock has been released, you could open it and
ensure your copy has succeeded.  Just a thought....
~~~~~~~~~~~~~~~~~~~~~~~
import thread
def counter(myId, count):
 for i in range(count):
    stdoutmutex.acquire()
    #Copy Your File Here
    stdoutmutex.release()
 exitmutexes[myId].acquire()


stdoutmutex = thread.allocate_lock()
exitmutexes = []
for i in range(2):
   exitmutexes.append(thread.allocate_lock())
   thread.start_new(counter, (i, 2))

for mutex in exitmutexes:
   while not mutex.locked():
       #Open Your File Here

print 'Exiting'



On 1/30/07, Hugo Ferreira <bytter at gmail.com> wrote:
>
> Hi there,
>
> I have a problem. I'm using calling shutil.copyfile() followed by
> open(). The thing is that most of the times open() is called before
> the actual file is copied. I don't have this problem when doing a
> step-by-step debug, since I give enough time for the OS to copy the
> file, but at run-time, it throws an exception.
>
> Is there anyway to force a sync copy of the file (make python wait for
> the completion)?
>
> Thanks in advance!
>
> Hugo Ferreira
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070130/d532fd94/attachment.html>


More information about the Python-list mailing list