将[{},{}]转为dict
python排列*号

用python检测文件是否正在被修改

妙音 posted @ 2013年11月17日 23:07 in python , 6104 阅读

使用lsof filename 可以查询到文件正在被谁使用。下面是python实现的检测代码。

a.py检测代码

#encoding=utf-8
import os


def isOpen(filename):
    # 执行lsof命令
    p = os.popen("lsof %s" % filename)
    # lsof找到打开的文件时有输出
    content = p.read()
    p.close()
    # 通过是否有输出,判断文件是否打开
    return bool(len(content))

if __name__ == '__main__':
    print isOpen("a.log")

b.py模拟正在修改文件

#encoding=utf-8
import time

if __name__ == '__main__':
    f = open("a.log", 'a')
    while True:
        time.sleep(5)

注意只能检测到文件被谁打开的情况。在python中就是open()了一个文件,并且还没有close()掉的情况。

以下情况是检测不到的:

vim xxx

python xxx

上面是比较简陋的一种方式,更强大的功能请见pyinotify模块

Avatar_small
依云 说:
2013年11月18日 00:12

要检测到文件操作用 pyinotify 嘛。

Avatar_small
top tech 说:
2020年10月08日 19:20

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.

Avatar_small
Best10 说:
2020年10月09日 22:55

Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome!

Avatar_small
ytmp26 说:
2020年10月10日 15:36

Thanks for taking the time to discuss this, I feel strongly that love and read more on this topic. If possible, such as gain knowledge, would you mind updating your blog with additional information? It is very useful for me.

Avatar_small
Capital Gains Tax Ad 说:
2020年10月11日 01:23

Great article with excellent idea!Thank you for such a valuable article. I really appreciate for this great information..

Avatar_small
Tax Advisors Tax Acc 说:
2020年10月12日 01:43

It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing.

Avatar_small
f88tw 说:
2020年10月12日 15:19

敬启者:个人小网站希望大家多多支持 感谢您对我们热心的支持 f88tw┃华歌尔┃I appreciate your kind assistance. f88tw|墓园|捡骨流程|捡骨费用|捡骨时间|禁忌|捡骨颜色|捡骨师|新竹|时间|台北|桃园|苗栗|头份|火化|晋塔|安葬|法事|捡骨|看日子|墓穴|墓园|坟墓|看日子|乞丐|http://mypaper.m.pchome.com.tw/f88tw

Avatar_small
sa gaming 1688 说:
2020年10月12日 21:38

howdy, your websites are really good. I appreciate your work.

Avatar_small
บาคาร่า เล่นยังไง 说:
2020年10月12日 21:38

Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day!

Avatar_small
Mab instructor cours 说:
2020年10月13日 15:28

Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

Avatar_small
נערות ליוי בחיפה 说:
2020年10月14日 18:29

I have a hard time describing my thoughts on content, but I really felt I should here. Your article is really great. I like the way you wrote this information.

Avatar_small
Bigg boss tamil vote 说:
2020年10月15日 14:52

Very good points you wrote here..Great stuff...I think you've made some truly interesting points.Keep up the good work.

Avatar_small
back scratcher amazo 说:
2020年10月16日 18:37

Some subdivisions thus dissertation web site using the net literature need unsurprisingly explained in your web-site.

Avatar_small
telescopic back scra 说:
2020年10月18日 00:30

There are a number dissertation web sites on line any time you see unsurprisingly labeled in the internet site.

Avatar_small
Oliviaseo 说:
2020年10月18日 15:31

Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging.. สล็อต

Avatar_small
Oliviaseo 说:
2020年10月18日 19:50

Your work is very good and I appreciate you and hopping for some more informative posts. Thank you for sharing great information to us. Reliable Instagram Followers

Avatar_small
Oliviaseo 说:
2020年10月19日 20:27

You completed a few fine points there. I did a search on the subject and found nearly all persons will go along with with your blog. สล็อต xo

Avatar_small
Oliviaseo 说:
2020年10月20日 15:38

Please continue this great work and I look forward to more of your awesome blog posts. แก้ปัญหา sbobet

Avatar_small
Oliviaseo 说:
2020年10月20日 23:20

It’s appropriate time to make some plans for the future and it is time to be happy. I have read this post and if I could I wish to suggest you few interesting things or advice. Perhaps you could write next articles referring to this article. I desire to read even more things about it! fitness gifts

Avatar_small
https://www.alltopte 说:
2020年10月21日 23:23

Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.

Avatar_small
Oliviaseo 说:
2020年10月23日 20:27

Thank you very much for writing such an interesting article on this topic. This has really made me think and I hope to read more. magicien mentaliste Lyon

Avatar_small
Oliviaseo 说:
2020年10月24日 02:35

I learn some new stuff from it too, thanks for sharing your information. properties for sale Kenya

Avatar_small
Oliviaseo 说:
2020年10月24日 19:02

I am continually amazed by the amount of information available on this subject. What you presented was well researched and well worded in order to get your stand on this across to all your readers. global magazine

Avatar_small
Oliviaseo 说:
2020年10月25日 19:26

Thank you for taking the time to publish this information very useful! escort girls in Canada

Avatar_small
Oliviaseo 说:
2020年10月25日 19:43

Admiring the time and effort you put into your blog and detailed information you offer!.. escort girls in Germany

Avatar_small
Oliviaseo 说:
2020年10月25日 21:18

I have recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time & work. escort girls in Austria

Avatar_small
Oliviaseo 说:
2020年10月25日 21:27

An fascinating discussion is value comment. I think that it is best to write extra on this matter, it won’t be a taboo topic however generally people are not enough to talk on such topics. To the next. Cheers escort girls in China

Avatar_small
Oliviaseo 说:
2020年10月25日 21:33

I think this is an informative post and it is very beneficial and knowledgeable. Therefore, I would like to thank you for the endeavors that you have made in writing this article. All the content is absolutely well-researched. Thanks... escort girls in France

Avatar_small
Oliviaseo 说:
2020年10月25日 21:40

I am thankful to you for sharing this plethora of useful information. I found this resource utmost beneficial for me. Thanks a lot for hard work. escort girls in Russia

Avatar_small
Oliviaseo 说:
2020年10月25日 21:44

I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. escort girls in UK

Avatar_small
Oliviaseo 说:
2020年10月25日 21:49

This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post! <a href="https://escortfox.com/escorts/TH">escort girls in Thailand</a>

Avatar_small
Oliviaseo 说:
2020年10月28日 19:18

Merely a smiling visitant here to share the love (:, btw outstanding style. great expectations pdf

Avatar_small
Oliviaseo 说:
2020年10月31日 15:34

It is my first visit to your blog, and I am very impressed with the articles that you serve. Give adequate knowledge for me. Thank you for sharing useful material. I will be back for the more great post. Insurance quotes

Avatar_small
Oliviaseo 说:
2020年10月31日 22:28

Thank you for such a well written article. It’s full of insightful information and entertaining descriptions. Your point of view is the best among many. Buy viagra in Australia

Avatar_small
Oliviaseo 说:
2020年11月01日 22:43

Awesome article! I want people to know just how good this information is in your article. It’s interesting, compelling content. Your views are much like my own concerning this subject. situs judi online

Avatar_small
Oliviaseo 说:
2020年11月02日 20:18

Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.. buy instagram views

Avatar_small
buy youtube likes 说:
2020年11月04日 22:12

Cool you inscribe, the info is really salubrious further fascinating, I'll give you a connect to my scene.

Avatar_small
Oliviaseo 说:
2020年11月05日 02:13

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing yahoo mail support

Avatar_small
houston embroidery s 说:
2020年11月07日 14:41

That's in addition a great publish which i really valued learning. It's not every day that people maintain the opportunity to discover something.

Avatar_small
Oliviaseo 说:
2020年11月07日 16:00

This blog is really great. The information here will surely be of some help to me. Thanks!. hote-mail website

Avatar_small
Oliviaseo 说:
2020年11月08日 20:52

this is really nice to read..informative post is very good to read..thanks a lot! new zealand eta

Avatar_small
Oliviaseo 说:
2020年11月10日 16:03

Thank you very much for this great post. get ingo

Avatar_small
สล็อต ออนไลน์ 说:
2020年11月10日 20:05

<a href="https://royalwallet789.com/register.html">สล็อต ออนไลน์? </a>

Avatar_small
Oliviaseo 说:
2020年11月10日 20:56

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. <a href="https://caregivercertificationonlinecourse.com/nrp-certification-course-online">nrp nrp recertification</a>

Avatar_small
Oliviaseo 说:
2020年11月12日 14:50

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. 먹튀플러스

Avatar_small
Oliviaseo 说:
2020年11月12日 19:34

You understand your projects stand out of the crowd. There is something unique about them. It seems to me all of them are brilliant. manuall quality

Avatar_small
Oliviaseo 说:
2020年11月12日 21:00

This was really an interesting topic and I kinda agree with what you have mentioned here! here

Avatar_small
delete sugardaddyfor 说:
2020年11月13日 12:07

Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.

Avatar_small
blog comment 说:
2020年11月13日 18:32

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.

Avatar_small
Oliviaseo 说:
2020年11月14日 15:39

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! Kadavi

Avatar_small
Question Paper 2021 说:
2020年11月16日 14:44

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me.

Avatar_small
Oliviaseo 说:
2020年11月17日 15:26

very interesting keep posting. naked url

Avatar_small
Oliviaseo 说:
2020年11月18日 15:14

Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. леруа каталог

Avatar_small
Oliviaseo 说:
2020年11月18日 16:01

It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing. naked url

Avatar_small
Oliviaseo 说:
2020年11月18日 19:44

Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. click this link here now

Avatar_small
Oliviaseo 说:
2020年11月18日 20:49

I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. recommended reading

Avatar_small
Oliviaseo 说:
2020年11月21日 18:12

it was a wonderful chance to visit this kind of site and I am happy to know. thank you so much for giving us a chance to have this opportunity.. here

Avatar_small
Oliviaseo 说:
2020年11月23日 15:58

All your hard work is much appreciated. Nobody can stop to admire you. Lots of appreciation. see this page

Avatar_small
rastreamento veicula 说:
2020年11月26日 19:39

Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.

Avatar_small
Oliviaseo 说:
2020年11月28日 20:11

Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it. Male extra

Avatar_small
KBC WhatsApp Lottery 说:
2020年11月30日 19:26

I am always searching online for storys that can accommodate me. There is obviously a multiple to understand about this. I feel you made few salubrious points in Attributes moreover. Detain busy, awesome career!

Avatar_small
jack 说:
2020年12月01日 15:40

This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!. viagra

Avatar_small
best sifter 说:
2020年12月04日 19:27

There are various dissertation internet websites online if you come across not surprisingly defined as part of your site.

Avatar_small
old flour sifter 说:
2020年12月04日 20:02

There are plenty of dissertation web sites over the internet while you obtain not surprisingly detailed in the webpage.

Avatar_small
real estate 说:
2020年12月05日 17:13

These you will then see the most important thing, the application provides you a website a powerful important internet page:

Avatar_small
Oliviaseo 说:
2020年12月05日 20:57

i love reading this article so beautiful!!great job! buy psilocin pills online

Avatar_small
Oliviaseo 说:
2020年12月06日 15:42

I just couldn't leave your website before telling you that I truly enjoyed the top quality info you present to your visitors? Will be back again frequently to check up on new posts. more info in cctv camers

Avatar_small
Oliviaseo 说:
2020年12月06日 19:24

This is my first time visit here. From the tons of comments on your articles,I guess I am not only one having all the enjoyment right here! mieszkania na sprzedaz

Avatar_small
Oliviaseo 说:
2020年12月07日 16:33

I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates. get more info about purchasing

Avatar_small
Oliviaseo 说:
2020年12月12日 18:57

I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot! vimax pills

Avatar_small
Oliviaseo 说:
2020年12月13日 21:45

Hi there! Nice stuff, do keep me posted when you post again something like this! https://totalwebdisaster.co.uk/2020/12/02/real-estate-lingo-in-singapore/

Avatar_small
Fitness tips 说:
2020年12月14日 19:41

It is especially decent, though look into the tips during this home address.

Avatar_small
Oliviaseo 说:
2020年12月16日 20:12

Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. filmtoon

Avatar_small
Oliviaseo 说:
2020年12月17日 18:37

Thanks for sharing this quality information with us. I really enjoyed reading. Will surely going to share this URL with my friends. Director of staff development course

Avatar_small
Oliviaseo 说:
2020年12月19日 18:56

No doubt this is an excellent post I got a lot of knowledge after reading good luck. Theme of blog is excellent there is almost everything to read, Brilliant post. Aleks Answers

Avatar_small
Oliviaseo 说:
2020年12月20日 19:13

Very nice article, I enjoyed reading your post, very nice share, I want to twit this to my followers. Thanks!. nieruchomosci kielce

Avatar_small
Oliviaseo 说:
2020年12月21日 18:34

I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. sisteme de copiat

Avatar_small
Oliviaseo 说:
2020年12月23日 00:16

Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. biura nieruchomosci gdansk

Avatar_small
Oliviaseo 说:
2020年12月24日 15:35

Succeed! It could be one of the most useful blogs we have ever come across on the subject. Excellent info! I’m also an expert in this topic so I can understand your effort very well. Thanks for the huge help. swiadectwa energetyczne szczecin

Avatar_small
johnyking 说:
2020年12月29日 02:16

This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff. phim heo

Avatar_small
johnyking 说:
2021年1月01日 02:41

I can set up my new idea from this post. It gives in depth information. Thanks for this valuable information for all,.. modny rower

Avatar_small
johnyking 说:
2021年1月03日 02:00

I just want to let you know that I just check out your site and I find it very interesting and informative.. nieruchomosci szczecin

Avatar_small
old flour sifter 说:
2021年1月03日 15:29

Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors.

Avatar_small
johnyking 说:
2021年1月05日 02:12

Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up. rowery damskie

Avatar_small
back scratcher shoe 说:
2021年1月05日 12:33

You'll find so many dissertation sites on the net when you get relatively observed inside the website.

Avatar_small
Oliviaseo 说:
2021年1月05日 17:28

I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. <a href="https://uholinex.pl/">wyburzenia hal</a>

Avatar_small
Oliviaseo 说:
2021年1月05日 20:20

A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. koszalin biuro nieruchomosci

Avatar_small
voyance par telephon 说:
2021年1月09日 18:43

Mmm.. estimable to be here in your report or notify, whatever, I repute I should moreover process strong for my have website want I play some salubrious further updated busy in your location.

Avatar_small
johnyking 说:
2021年1月11日 19:20

I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. 먹튀검증사이트

Avatar_small
johnyking 说:
2021年1月13日 00:57

Great content material and great layout. Your website deserves all of the positive feedback it’s been getting. Lambingan

Avatar_small
warisak 说:
2021年1月13日 13:25

There are particular dissertation websites on the internet should you acquire certainly introduced in your web page. เครดิตฟรี

Avatar_small
johnyking 说:
2021年1月13日 19:34

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing visit here

Avatar_small
johnyking 说:
2021年1月14日 14:40

I think this is a really good article. You make this information interesting and engaging. You give readers a lot to think about and I appreciate that kind of writing. voyance par telephone gratuite

Avatar_small
johnyking 说:
2021年1月15日 01:51

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. trendyol satış yükseltme

Avatar_small
voopoo drag 2 说:
2021年1月16日 18:35

Why do only so much written on this subject? Here you see more.

Avatar_small
we buy any motorhome 说:
2021年1月16日 18:43

Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work.

Avatar_small
Hand crafted 说:
2021年1月17日 18:56

Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!!

Avatar_small
johnyking 说:
2021年1月18日 02:25

I think this is a really good article. You make this information interesting and engaging. You give readers a lot to think about and I appreciate that kind of writing. agencia seo

Avatar_small
ligas de resistencia 说:
2021年1月18日 14:06

Thank you for the update, very nice site..

Avatar_small
johnyking 说:
2021年1月18日 21:20

I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information. instalacion de paneles solares

Avatar_small
johnyking 说:
2021年1月19日 14:53

I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information. vasos para micheladas

Avatar_small
bitcoin to paypal 说:
2021年1月20日 01:14

On this page you can read my interests, write something special.

Avatar_small
johnyking 说:
2021年1月20日 01:26

I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well! swingtrading

Avatar_small
Oliviaseo 说:
2021年1月21日 19:25

Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. situs judi online terpercaya

Avatar_small
Oliviaseo 说:
2021年1月23日 21:33

Thank you for helping people get the information they need. Great stuff as usual. Keep up the great work!!! Prestige Smart City

Avatar_small
johnyking 说:
2021年1月24日 19:28

Thanks for your information, it was really very helpful: daytrader

Avatar_small
johnyking 说:
2021年1月25日 14:39

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. bursa chat

Avatar_small
johnyking 说:
2021年1月26日 14:27

This was really an interesting topic and I kinda agree with what you have mentioned here! agen domino qq

Avatar_small
บาคาร่า 说:
2021年1月26日 18:24

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.

Avatar_small
johnyking 说:
2021年1月27日 01:07

It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing. บาคาร่าออนไลน์

Avatar_small
johnyking 说:
2021年1月27日 18:27

It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing. aktier for nyborjare

Avatar_small
Research Chemicals f 说:
2021年1月27日 23:04

Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter