[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

problems closing a CD

Tom Cloyd

3/4/2008 10:59:00 AM

I'm utterly baffled by this simple problem in a ruby program I've run a
number of time on Windows. I'm now running Kubuntu Linux, and things
work differently (!).

This program reads a series of data CDs, cataloging their contents. To
stop the process, I input a zero length volume label (well, on Windows I
do, anyway; on Linux this errors off, but that's not my current problem).

What I can't do is get the CD just read in to be released by the program
so I can read in the next one.

Code:

> archive_source_dir = '/cdrom' # this is where the CD appears when I
put it in the drive

Processing begins when the program has the volume label of the CD (this
is used as the key in a hash containing an array of the tree paths).
When it has traversed the directory tree on the CD, it asks for the next
volume label. In Windows, I just punch the open button on the drive,
replaced the CD with a new one, close the drive, keyed in the new volume
label, and kept going. Linux won't release the CD.

I've tried many things to get the CD to go release, including...
> archive_source_dir.close
> IO.close(archive_source_dir)
> File.close(archive_source_dir)

I get "undefined method" errors on everything. I have no idea why. Isn't
everything a file in linux? Guess not.

Plainly I'm missing some simple concept here, but I can't see it.

Would appreciate any help.

Tom



5 Answers

Jano Svitok

3/4/2008 11:29:00 AM

0

On Tue, Mar 4, 2008 at 11:58 AM, Tom Cloyd <tomcloyd@comcast.net> wrote:
> I'm utterly baffled by this simple problem in a ruby program I've run a
> number of time on Windows. I'm now running Kubuntu Linux, and things
> work differently (!).
>
> This program reads a series of data CDs, cataloging their contents. To
> stop the process, I input a zero length volume label (well, on Windows I
> do, anyway; on Linux this errors off, but that's not my current problem).
>
> What I can't do is get the CD just read in to be released by the program
> so I can read in the next one.
>
> Code:
>
> > archive_source_dir = '/cdrom' # this is where the CD appears when I
> put it in the drive
>
> Processing begins when the program has the volume label of the CD (this
> is used as the key in a hash containing an array of the tree paths).
> When it has traversed the directory tree on the CD, it asks for the next
> volume label. In Windows, I just punch the open button on the drive,
> replaced the CD with a new one, close the drive, keyed in the new volume
> label, and kept going. Linux won't release the CD.
>
> I've tried many things to get the CD to go release, including...
> > archive_source_dir.close
> > IO.close(archive_source_dir)
> > File.close(archive_source_dir)
>
> I get "undefined method" errors on everything. I have no idea why. Isn't
> everything a file in linux? Guess not.
>
> Plainly I'm missing some simple concept here, but I can't see it.
>
> Would appreciate any help.
>
> Tom

I guess this has something to do with mounting/umounting, though I
don't know too much about automatic mounting in kubuntu.
Try using `umount /cdrom` after you are done. (Don't forget to close
any open files and move away from that dir).
You might encounter some privileges problems ("only root can do") -
try sudo in that case, or modify /etc/fstab to allow users to
mount/umount.

`eject` and `eject -t` might be useful as well.

Tom Cloyd

3/4/2008 12:15:00 PM

0

Jano Svitok wrote:
> On Tue, Mar 4, 2008 at 11:58 AM, Tom Cloyd <tomcloyd@comcast.net> wrote:
>
>> I'm utterly baffled by this simple problem in a ruby program I've run a
>> number of time on Windows. I'm now running Kubuntu Linux, and things
>> work differently (!).
>>
>> This program reads a series of data CDs, cataloging their contents. To
>> stop the process, I input a zero length volume label (well, on Windows I
>> do, anyway; on Linux this errors off, but that's not my current problem).
>>
>> What I can't do is get the CD just read in to be released by the program
>> so I can read in the next one.
>>
>> Code:
>>
>> > archive_source_dir = '/cdrom' # this is where the CD appears when I
>> put it in the drive
>>
>> Processing begins when the program has the volume label of the CD (this
>> is used as the key in a hash containing an array of the tree paths).
>> When it has traversed the directory tree on the CD, it asks for the next
>> volume label. In Windows, I just punch the open button on the drive,
>> replaced the CD with a new one, close the drive, keyed in the new volume
>> label, and kept going. Linux won't release the CD.
>>
>> I've tried many things to get the CD to go release, including...
>> > archive_source_dir.close
>> > IO.close(archive_source_dir)
>> > File.close(archive_source_dir)
>>
>> I get "undefined method" errors on everything. I have no idea why. Isn't
>> everything a file in linux? Guess not.
>>
>> Plainly I'm missing some simple concept here, but I can't see it.
>>
>> Would appreciate any help.
>>
>> Tom
>>
>
> I guess this has something to do with mounting/umounting, though I
> don't know too much about automatic mounting in kubuntu.
> Try using `umount /cdrom` after you are done. (Don't forget to close
> any open files and move away from that dir).
> You might encounter some privileges problems ("only root can do") -
> try sudo in that case, or modify /etc/fstab to allow users to
> mount/umount.
>
> `eject` and `eject -t` might be useful as well.
>
>
>
The problem is that I need an unmount WHILE the program is running, and
it won't let go of the device. When I tried to close it, ruby refuses to
acknowledge knowing anything about "close". It appears that there is no
kernal#close, suddenly. Nothing works. I open the device and cannot shut
it down. If I try to do this through Linux, while my program is running,
I get "umount: /media/cdrom0: device is busy". It's a ruby problem - or
rather my problem in using ruby.

So, again...having done this
>archive_source_dir = '/cdrom'
how do I "undo" it?


Any more ideas?

Thanks,

Tom

Jano Svitok

3/4/2008 1:07:00 PM

0

On Tue, Mar 4, 2008 at 1:15 PM, Tom Cloyd <tomcloyd@comcast.net> wrote:
>
> Jano Svitok wrote:
> > On Tue, Mar 4, 2008 at 11:58 AM, Tom Cloyd <tomcloyd@comcast.net> wrote:
> >
> >> I'm utterly baffled by this simple problem in a ruby program I've run a
> >> number of time on Windows. I'm now running Kubuntu Linux, and things
> >> work differently (!).
> >>
> >> This program reads a series of data CDs, cataloging their contents. To
> >> stop the process, I input a zero length volume label (well, on Windows I
> >> do, anyway; on Linux this errors off, but that's not my current problem).
> >>
> >> What I can't do is get the CD just read in to be released by the program
> >> so I can read in the next one.
> >>
> >> Code:
> >>
> >> > archive_source_dir = '/cdrom' # this is where the CD appears when I
> >> put it in the drive
> >>
> >> Processing begins when the program has the volume label of the CD (this
> >> is used as the key in a hash containing an array of the tree paths).
> >> When it has traversed the directory tree on the CD, it asks for the next
> >> volume label. In Windows, I just punch the open button on the drive,
> >> replaced the CD with a new one, close the drive, keyed in the new volume
> >> label, and kept going. Linux won't release the CD.
> >>
> >> I've tried many things to get the CD to go release, including...
> >> > archive_source_dir.close
> >> > IO.close(archive_source_dir)
> >> > File.close(archive_source_dir)
> >>
> >> I get "undefined method" errors on everything. I have no idea why. Isn't
> >> everything a file in linux? Guess not.
> >>
> >> Plainly I'm missing some simple concept here, but I can't see it.
> >>
> >> Would appreciate any help.
> >>
> >> Tom
> >>
> >
> > I guess this has something to do with mounting/umounting, though I
> > don't know too much about automatic mounting in kubuntu.
> > Try using `umount /cdrom` after you are done. (Don't forget to close
> > any open files and move away from that dir).
> > You might encounter some privileges problems ("only root can do") -
> > try sudo in that case, or modify /etc/fstab to allow users to
> > mount/umount.
> >
> > `eject` and `eject -t` might be useful as well.
> >
> >
> >
> The problem is that I need an unmount WHILE the program is running, and
> it won't let go of the device. When I tried to close it, ruby refuses to
> acknowledge knowing anything about "close". It appears that there is no
> kernal#close, suddenly. Nothing works. I open the device and cannot shut
> it down. If I try to do this through Linux, while my program is running,
> I get "umount: /media/cdrom0: device is busy". It's a ruby problem - or
> rather my problem in using ruby.
>
> So, again...having done this
> >archive_source_dir = '/cdrom'
> how do I "undo" it?
>
>
> Any more ideas?

1. lsof will show you your process' open files.
2. Make sure to use block form of File.open instead of File.new - it
will close the file when you're done with it.
3. Instead of archive_source_dir.close() do Dir.chdir('/') or
somewhere else. Or even better, use block form of Dir.chdir if you
need to chdir into
/cdrom
4. if you could post minimal program that makes trouble, maybe some
more ideas will pop up. (e.g. strip as much as you can while it still
causes the problem - I guess just traversing the CD will be enough)

Tom Cloyd

3/7/2008 5:04:00 AM

0

Jano Svitok wrote:
> On Tue, Mar 4, 2008 at 1:15 PM, Tom Cloyd <tomcloyd@comcast.net> wrote:
>
>> Jano Svitok wrote:
>> > On Tue, Mar 4, 2008 at 11:58 AM, Tom Cloyd <tomcloyd@comcast.net> wrote:
>> >
>> >> I'm utterly baffled by this simple problem in a ruby program I've run a
>> >> number of time on Windows. I'm now running Kubuntu Linux, and things
>> >> work differently (!).
>> >>
>> >> This program reads a series of data CDs, cataloging their contents. To
>> >> stop the process, I input a zero length volume label (well, on Windows I
>> >> do, anyway; on Linux this errors off, but that's not my current problem).
>> >>
>> >> What I can't do is get the CD just read in to be released by the program
>> >> so I can read in the next one.
>> >>
>> >> Code:
>> >>
>> >> > archive_source_dir = '/cdrom' # this is where the CD appears when I
>> >> put it in the drive
>> >>
>> >> Processing begins when the program has the volume label of the CD (this
>> >> is used as the key in a hash containing an array of the tree paths).
>> >> When it has traversed the directory tree on the CD, it asks for the next
>> >> volume label. In Windows, I just punch the open button on the drive,
>> >> replaced the CD with a new one, close the drive, keyed in the new volume
>> >> label, and kept going. Linux won't release the CD.
>> >>
>> >> I've tried many things to get the CD to go release, including...
>> >> > archive_source_dir.close
>> >> > IO.close(archive_source_dir)
>> >> > File.close(archive_source_dir)
>> >>
>> >> I get "undefined method" errors on everything. I have no idea why. Isn't
>> >> everything a file in linux? Guess not.
>> >>
>> >> Plainly I'm missing some simple concept here, but I can't see it.
>> >>
>> >> Would appreciate any help.
>> >>
>> >> Tom
>> >>
>> >
>> > I guess this has something to do with mounting/umounting, though I
>> > don't know too much about automatic mounting in kubuntu.
>> > Try using `umount /cdrom` after you are done. (Don't forget to close
>> > any open files and move away from that dir).
>> > You might encounter some privileges problems ("only root can do") -
>> > try sudo in that case, or modify /etc/fstab to allow users to
>> > mount/umount.
>> >
>> > `eject` and `eject -t` might be useful as well.
>> >
>> >
>> >
>> The problem is that I need an unmount WHILE the program is running, and
>> it won't let go of the device. When I tried to close it, ruby refuses to
>> acknowledge knowing anything about "close". It appears that there is no
>> kernal#close, suddenly. Nothing works. I open the device and cannot shut
>> it down. If I try to do this through Linux, while my program is running,
>> I get "umount: /media/cdrom0: device is busy". It's a ruby problem - or
>> rather my problem in using ruby.
>>
>> So, again...having done this
>> >archive_source_dir = '/cdrom'
>> how do I "undo" it?
>>
>>
>> Any more ideas?
>>
>
> 1. lsof will show you your process' open files.
> 2. Make sure to use block form of File.open instead of File.new - it
> will close the file when you're done with it.
> 3. Instead of archive_source_dir.close() do Dir.chdir('/') or
> somewhere else. Or even better, use block form of Dir.chdir if you
> need to chdir into
> /cdrom
> 4. if you could post minimal program that makes trouble, maybe some
> more ideas will pop up. (e.g. strip as much as you can while it still
> causes the problem - I guess just traversing the CD will be enough)
>
>
>
Jano,
I'm slow getting back to this, but will in the next couple of hours.
Thank you for your promising ideas. I can see that they are likely to
get things moving on this problem, which I do need to solve. I'm
grateful for your help, and will get back to you with what I learn. I'm
thinking I'm close to a solution at this point.

Tom

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Pawel Kierski

4/28/2014 8:51:00 AM

0

W dniu 2014-04-25 20:03, Borneq pisze:
> W dniu 2014-04-25 20:01, Wojciech Mu?a pisze:
>> Ale dlaczego to jest problemem? Te dane nie mieszcz? si? dost?pnej
>> pami?ci?
>
> dla bardzo du?ych plik?w mog? si? nie zmie?ci?
>

Zak?adam, ?e plik mo?na raz obrobi? na pocz?tku.

Przesortowa? plik wg ID. Podzieli? na bloki po k punkt?w (zrobi? indeks
ID dla 0, 999, 1999 itd. punktu w pliku, je?li dzielisz co 1000). Ka?dy
z tych blok?w b?dzie mia? z g?ry ograniczony rozmiar, dzi?ki czemu
?atwo b?dzie zrobi? cache - czyta? po bloku i trzyma? ostatnio czytane
w pami?ci.

--
Pawe? Kierski
news@pkierski.net