确定文件何时完成复制 [英] Determining when a file has finished copying

查看:57
本文介绍了确定文件何时完成复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在编写一些代码,用于监视目录中是否存在来自工作流的

文件。当这些文件出现时,我将命令文件

写入设备,告诉设备如何处理文件。命令文件的

外观触发设备获取

原始文件。我的问题是我不想把命令文件写到

设备,直到工作流程中的原始文件被完全复制完毕。由于这些文件很大,我的程序很有可能扫描目录时是
,因为我需要

来确定哪些文件被复制完毕还有什么呢?
中期副本。


我在Google上没有看到任何关于此事的内容,我也看不到/>
使用

文件路径上的os.stat()方法执行此操作的明显方法。任何人对我如何做到这一点都有任何想法吗?


提前致谢!

Doug

解决方案

writeson写道:


大家好,


我正在写一些监视器的代码工作流程中出现

文件的目录。当这些文件出现时,我将命令文件

写入设备,告诉设备如何处理文件。命令文件的

外观触发设备获取

原始文件。我的问题是我不想把命令文件写到

设备,直到工作流程中的原始文件被完全复制完毕。由于这些文件很大,我的程序很有可能扫描目录时是
,因为我需要

来确定哪些文件被复制完毕还有什么呢?
中期副本。


我在Google上没有看到任何关于此事的内容,我也看不到/>
使用

文件路径上的os.stat()方法执行此操作的明显方法。任何人对我如何做到这一点都有任何想法吗?


提前致谢!

Doug



执行此操作的最佳方法是让复制文件的程序将它们复制到临时命名的文件中,并在完成时将其重命名。这样你就可以通过扫描具有特定掩码的文件来了解它是什么时候。


如果不可能,你可以使用pyinotify

http://pyinotify.sourceforge.net/ )在

目录上观察WRITE_CLOSE事件,然后处理这些文件。


-Larry


blockquote>

----- BEGIN PGP签名消息-----

哈希:SHA1


这似乎是同步问题。一个场景描述可以清除

所以我们可以提供帮助:


程序W(工作流程)将文件F复制到目录B

程序D(狗)轮询目录B找到是否有任何新文件F


在这种情况下,程序D不知道F是否已完全

复制,但W确实如此。


解决方案:

创建自定义锁机制。程序W将文件D / F.lock写入

表示文件F未完成,当F完全复制时它被删除。

我程序W崩溃了中期复制F和F.lock都保留,所以程序D

不打算处理F.从W中崩溃恢复另一个

问题来解决。


祝你好运,

Manuel。


writeson写道:


大家好,


我正在编写一些代码来监视目录,以便从工作流程中查看

文件的外观。当这些文件出现时,我将命令文件

写入设备,告诉设备如何处理文件。命令文件的

外观触发设备获取

原始文件。我的问题是我不想把命令文件写到

设备,直到工作流程中的原始文件被完全复制完毕。由于这些文件很大,我的程序很有可能扫描目录时是
,因为我需要

来确定哪些文件被复制完毕还有什么呢?
中期副本。


我在Google上没有看到任何关于此事的内容,我也看不到/>
使用

文件路径上的os.stat()方法执行此操作的明显方法。任何人对我如何做到这一点都有任何想法吗?


提前致谢!

Doug

-
http://mail.python.org/mailman/listinfo/python-清单



----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.4.9(GNU / Linux)

评论:将GnuPG与Mozilla一起使用 - http:// enigmail。 mozdev.org


iEYEARECAAYFAkh04skACgkQI2zpkmcEAhi0eQCgsVqg51fWiw i47jxqtbR8Gz2U

UukAoKm15UAm3KpEyjhsIGQ + 68rq8WuU

= UFHi

-----结束PGP SIGNATURE -----




也有:

pgm-W复制/创建 - 填写任何B /假

完成后,pgm-W将B /假名重命名为B / F

pgm-D只为B / F侦察并且确实找到的东西


史蒂夫
没有****** @ hughes.net

Manuel Vazquez Acosta写道:


----- BEGIN PGP签名消息-----

哈希:SHA1


这似乎是一个同步问题。一个场景描述可以清除

所以我们可以提供帮助:


程序W(工作流程)将文件F复制到目录B

程序D(狗)轮询目录B找到是否有任何新文件F


在这种情况下,程序D不知道F是否已完全

复制,但W确实如此。


解决方案:

创建自定义锁机制。程序W将文件D / F.lock写入

表示文件F未完成,当F完全复制时它被删除。

我程序W崩溃了中期复制F和F.lock都保留,所以程序D

不打算处理F.从W中崩溃恢复另一个

问题来解决。


祝你好运,

Manuel。


writeson写道:


>大家好,

我正在编写一些代码来监视目录,以便从工作流程中看到
文件的外观。当这些文件出现时,我将命令文件写入设备,告诉设备如何处理文件。命令文件的外观会触发设备获取原始文件。我的问题是我不想将命令文件写入设备,直到工作流程中的原始文件被完全复制完毕。由于这些文件很大,我的程序很有可能在目录复制时扫描目录,所以我需要确定哪些文件已经完成复制,哪些文件仍然是
mid-copy。

谷歌没有看到任何关于这个问题的内容,我也没有看到使用os.stat()方法做这件事的明显方法在
文件路径上。任何人对我如何做到这一点都有任何想法吗?

提前致谢!
道格
-
http://mail.python.org/mailman/listinfo/python-list


-----开始PGP SIGNATURE -----

版本:GnuPG v1.4.9(GNU / Linux)

评论:将GnuPG与Mozilla一起使用 - http://enigmail.mozdev.org
< br $>
iEYEARECAAYFAkh04skACgkQI2zpkmcEAhi0eQCgsVqg51fWiw i47jxqtbR8Gz2U

UukAoKm15UAm3KpEyjhsIGQ + 68rq8WuU

= UFHi

----- END PGP SIGNATURE ---- -

-
http ://mail.python.org/mailman/listinfo/python-list


Hi all,

I''m writing some code that monitors a directory for the appearance of
files from a workflow. When those files appear I write a command file
to a device that tells the device how to process the file. The
appearance of the command file triggers the device to grab the
original file. My problem is I don''t want to write the command file to
the device until the original file from the workflow has been copied
completely. Since these files are large, my program has a good chance
of scanning the directory while they are mid-copy, so I need to
determine which files are finished being copied and which are still
mid-copy.

I haven''t seen anything on Google talking about this, and I don''t see
an obvious way of doing this using the os.stat() method on the
filepath. Anyone have any ideas about how I might accomplish this?

Thanks in advance!
Doug

解决方案

writeson wrote:

Hi all,

I''m writing some code that monitors a directory for the appearance of
files from a workflow. When those files appear I write a command file
to a device that tells the device how to process the file. The
appearance of the command file triggers the device to grab the
original file. My problem is I don''t want to write the command file to
the device until the original file from the workflow has been copied
completely. Since these files are large, my program has a good chance
of scanning the directory while they are mid-copy, so I need to
determine which files are finished being copied and which are still
mid-copy.

I haven''t seen anything on Google talking about this, and I don''t see
an obvious way of doing this using the os.stat() method on the
filepath. Anyone have any ideas about how I might accomplish this?

Thanks in advance!
Doug

The best way to do this is to have the program that copies the files copy them
to a temporarily named file and rename it when it is completed. That way you
know when it is done by scanning for files with a specific mask.

If that is not possible you might be able to use pyinotify
(http://pyinotify.sourceforge.net/) to watch for WRITE_CLOSE events on the
directory and then process the files.

-Larry


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This seems a synchronization problem. A scenario description could clear
things up so we can help:

Program W (The workflow) copies file F to directory B
Program D (the dog) polls directory B to find is there''s any new file F

In this scenario, program D does not know whether F has been fully
copied, but W does.

Solution:
Create a custom lock mechanism. Program W writes a file D/F.lock to
indicate file F is not complete, it''s removed when F is fully copied.
I program W crashes in mid-copy both F and F.lock are kept so program D
does not bother to process F. Recovery from the crash in W would another
issue to tackle down.

Best regards,
Manuel.

writeson wrote:

Hi all,

I''m writing some code that monitors a directory for the appearance of
files from a workflow. When those files appear I write a command file
to a device that tells the device how to process the file. The
appearance of the command file triggers the device to grab the
original file. My problem is I don''t want to write the command file to
the device until the original file from the workflow has been copied
completely. Since these files are large, my program has a good chance
of scanning the directory while they are mid-copy, so I need to
determine which files are finished being copied and which are still
mid-copy.

I haven''t seen anything on Google talking about this, and I don''t see
an obvious way of doing this using the os.stat() method on the
filepath. Anyone have any ideas about how I might accomplish this?

Thanks in advance!
Doug
--
http://mail.python.org/mailman/listinfo/python-list

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkh04skACgkQI2zpkmcEAhi0eQCgsVqg51fWiw i47jxqtbR8Gz2U
UukAoKm15UAm3KpEyjhsIGQ+68rq8WuU
=UFHi
-----END PGP SIGNATURE-----



Also available:
pgm-W copies/creates-fills whatever B/dummy
when done, pgm-W renames B/dummy to B/F
pgm-D only scouts for B/F and does it thing when found

Steve
no******@hughes.net
Manuel Vazquez Acosta wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This seems a synchronization problem. A scenario description could clear
things up so we can help:

Program W (The workflow) copies file F to directory B
Program D (the dog) polls directory B to find is there''s any new file F

In this scenario, program D does not know whether F has been fully
copied, but W does.

Solution:
Create a custom lock mechanism. Program W writes a file D/F.lock to
indicate file F is not complete, it''s removed when F is fully copied.
I program W crashes in mid-copy both F and F.lock are kept so program D
does not bother to process F. Recovery from the crash in W would another
issue to tackle down.

Best regards,
Manuel.

writeson wrote:

>Hi all,

I''m writing some code that monitors a directory for the appearance of
files from a workflow. When those files appear I write a command file
to a device that tells the device how to process the file. The
appearance of the command file triggers the device to grab the
original file. My problem is I don''t want to write the command file to
the device until the original file from the workflow has been copied
completely. Since these files are large, my program has a good chance
of scanning the directory while they are mid-copy, so I need to
determine which files are finished being copied and which are still
mid-copy.

I haven''t seen anything on Google talking about this, and I don''t see
an obvious way of doing this using the os.stat() method on the
filepath. Anyone have any ideas about how I might accomplish this?

Thanks in advance!
Doug
--
http://mail.python.org/mailman/listinfo/python-list


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkh04skACgkQI2zpkmcEAhi0eQCgsVqg51fWiw i47jxqtbR8Gz2U
UukAoKm15UAm3KpEyjhsIGQ+68rq8WuU
=UFHi
-----END PGP SIGNATURE-----
--
http://mail.python.org/mailman/listinfo/python-list


这篇关于确定文件何时完成复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆