[Tutor] threading: getting latest elements from list/dict
Hello I have a thread updating a dictionary with new elements. How can I check for new elements as they are inserted into the dictionary by the thread? In general is it safe to read a dictionary or a list while it is being updated by a running thread? Does the dictionary or list have to be locked while reading? many questions! :) vaibhav ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] threading: getting latest elements from list/dict
Vaibhav.bhawsar wrote: Hello I have a thread updating a dictionary with new elements. How can I check for new elements as they are inserted into the dictionary by the thread? In general is it safe to read a dictionary or a list while it is being updated by a running thread? Does the dictionary or list have to be locked while reading? http://www.python.org/doc/faq/library/#what-kinds-of-global-value-mutation-are-thread-safe -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] free loop device
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hey Guys, I have a program that uses the loop devices. However I originally was finding the free one with: 'losetup -f'. Which returns the next free loop device. :D However, I found that some of the other distros have a version of losetup that does not include that switch. So I am trying to work up another way to get the next device. What I'm figuring is doing 'losetup -a', parsing the returned data, and incrementing it by one... However I don't know how to accomplish this. An example 'losetup -a' would be like this: [EMAIL PROTECTED] Desktop]# losetup -a /dev/loop0: [fd00]:11305639 (enc) /dev/loop1: [fd00]:11306533 (/home/nmcbride/Desktop/xxx.iso) Can anyone give me a hand? Thanks, Nate -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFIH2Oo/n+duykW6K8RAnCTAJ480KREx5udm22wFx3KbNQ08p6AeQCfcfoO IS+ZG3J8M1/oEjcHN/pLhU4= =5zQk -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for something similar to du...
Spencer Parker [EMAIL PROTECTED] wrote I am wondering if there is a way to do something that du does in Linux. I have several disk images and I need a way to get the size used...not the size of the image. If you type in du and the disk image path it gives you this number. is there anyway to do this in python? Probably but I'm not totally clear what you are looking for. Can you explain what you mean by the diffrence between the size used versus the size of the image? Surely the size of the image is the space it uses? Or are you expanding compressed files? Can you give an example of the two measures so that we(I?) can better understand the distinction Meantime try looking at the os.walk function and the os.fstat function. That may be all you need. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] free loop device
Nathan McBride wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hey Guys, I have a program that uses the loop devices. However I originally was finding the free one with: 'losetup -f'. Which returns the next free loop device. :D However, I found that some of the other distros have a version of losetup that does not include that switch. So I am trying to work up another way to get the next device. What I'm figuring is doing 'losetup -a', parsing the returned data, and incrementing it by one... However I don't know how to accomplish this. An example 'losetup -a' would be like this: [EMAIL PROTECTED] Desktop]# losetup -a /dev/loop0: [fd00]:11305639 (enc) /dev/loop1: [fd00]:11306533 (/home/nmcbride/Desktop/xxx.iso) Can anyone give me a hand? I for one have no idea how this relates to Python. If others do then they are likely to help you. -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for something similar to du...
On Mon, May 5, 2008 at 5:21 PM, Alan Gauld [EMAIL PROTECTED] wrote: Probably but I'm not totally clear what you are looking for. Can you explain what you mean by the diffrence between the size used versus the size of the image? Surely the size of the image is the space it uses? Or are you expanding compressed files? Disk space is allocated in large units (in DOS/Windows they're called clusters, *nixes call them blocks). A one-byte file still uses an entire cluster, whose size depends on the size of the disk and the number of chunks it can be divided into. So just knowing the size of the file is not quite enough information if you need to know how much room is left on the disk... If you use Windows, you can see this very easily - right-clicking on a JPEG file and selecting Properties, I get: Size: 35.1 KB (35,997 bytes) Size on disk: 48.0 KB (49,152 bytes) From the os.stat() docs: On some Unix systems (such as Linux), the following attributes may also be available: st_blocks (number of blocks allocated for file), st_blksize(filesystem blocksize), st_rdev (type of device if an inode device). st_flags (user defined flags for file). So apparently os.stat() can get this info from *nix, but not Windows... maybe behind the scenes, it runs du? -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] free loop device
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Yup, I got some help in IRC. What I ended up doing was using regex to pull out each /dev/loopX. Then took the X and fed it to max which in turn gave me the highest numbered loop device in use. After which I then just added 1 to X and added it to the end of /dev/loop_. The only other thing I had to do was put a check in incase there were no used loop devices in which case then it defaults to /dev/loop0. Works like a charm. :D Nate bob gailer wrote: Nathan McBride wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hey Guys, I have a program that uses the loop devices. However I originally was finding the free one with: 'losetup -f'. Which returns the next free loop device. :D However, I found that some of the other distros have a version of losetup that does not include that switch. So I am trying to work up another way to get the next device. What I'm figuring is doing 'losetup -a', parsing the returned data, and incrementing it by one... However I don't know how to accomplish this. An example 'losetup -a' would be like this: [EMAIL PROTECTED] Desktop]# losetup -a /dev/loop0: [fd00]:11305639 (enc) /dev/loop1: [fd00]:11306533 (/home/nmcbride/Desktop/xxx.iso) Can anyone give me a hand? I for one have no idea how this relates to Python. If others do then they are likely to help you. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFIH78C/n+duykW6K8RAuE3AJoDu69W1D7dldLPxXpCfRGuoc++FQCgj2G3 4fG0aSw7fe/noi4hqesG9oA= =vas+ -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for something similar to du...
Mark is right...in that I don't want the actual size of the file itself...that I can get from another way in Python which i am already doing. I was mainly wondering if there was a way to do it and I was just missing something. I looked though stat() and that is basically what I wanted. I wasn't sure if that was actually it until Mark spelled it out for me. I do love using du...since I am learning..I just wanted make sure I wasn't missing anything...thank you guys as always... On Mon, May 5, 2008 at 6:57 PM, Marc Tompkins [EMAIL PROTECTED] wrote: On Mon, May 5, 2008 at 5:21 PM, Alan Gauld [EMAIL PROTECTED] wrote: Probably but I'm not totally clear what you are looking for. Can you explain what you mean by the diffrence between the size used versus the size of the image? Surely the size of the image is the space it uses? Or are you expanding compressed files? Disk space is allocated in large units (in DOS/Windows they're called clusters, *nixes call them blocks). A one-byte file still uses an entire cluster, whose size depends on the size of the disk and the number of chunks it can be divided into. So just knowing the size of the file is not quite enough information if you need to know how much room is left on the disk... If you use Windows, you can see this very easily - right-clicking on a JPEG file and selecting Properties, I get: Size: 35.1 KB (35,997 bytes) Size on disk: 48.0 KB (49,152 bytes) From the os.stat() docs: On some Unix systems (such as Linux), the following attributes may also be available: st_blocks (number of blocks allocated for file), st_blksize(filesystem blocksize), st_rdev (type of device if an inode device). st_flags (user defined flags for file). So apparently os.stat() can get this info from *nix, but not Windows... maybe behind the scenes, it runs du? -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Spencer Parker ___ if you can't go to heaven, may you at least die in Ireland. ___ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor