comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » check if other routine is accessing a text file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
check if other routine is accessing a text file [message #88222] Sun, 30 March 2014 18:26 Go to next message
hoiting2008 is currently offline  hoiting2008
Messages: 4
Registered: March 2014
Junior Member
Hi,

I'm trying to read/write (openw,openu,openr) the same text file using multiple IDL prompts. The different prompts usually read/write the file at different time, but there is a tiny chance that they read/write at the same time. Is there any keywords or routines that can test if other program is using the file?

Ideally, I'd like to do something like this:

test_if_someone_writing?
yes: wait for 3 seconds and try again
no: go ahead and read/write

Thanks!
Re: check if other routine is accessing a text file [message #88223 is a reply to message #88222] Sun, 30 March 2014 19:42 Go to previous messageGo to next message
Jim  Pendleton is currently offline  Jim Pendleton
Messages: 165
Registered: November 2011
Senior Member
On Sunday, March 30, 2014 7:26:54 PM UTC-6, hoiti...@gmail.com wrote:
> Hi,
>
>
>
> I'm trying to read/write (openw,openu,openr) the same text file using multiple IDL prompts. The different prompts usually read/write the file at different time, but there is a tiny chance that they read/write at the same time. Is there any keywords or routines that can test if other program is using the file?
>
>
>
> Ideally, I'd like to do something like this:
>
>
>
> test_if_someone_writing?
>
> yes: wait for 3 seconds and try again
>
> no: go ahead and read/write
>
>
>
> Thanks!

There is nothing in IDL's file I/O library that will do this directly. You might consider using a semaphore around your openw and openr statements. See the docs for SEM_CREATE, SEM_LOCK, SEM_RELEASE, and SEM_DELETE. They're intended primarily to prevent conflicts and collisions on system resources, disk files included.

Jim P.
Re: check if other routine is accessing a text file [message #88224 is a reply to message #88223] Mon, 31 March 2014 08:14 Go to previous message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On Sunday, March 30, 2014 8:42:27 PM UTC-6, Jim P wrote:
> On Sunday, March 30, 2014 7:26:54 PM UTC-6, hoiti...@gmail.com wrote:
>
>> Hi,
>
>>
>
>>
>
>>
>
>> I'm trying to read/write (openw,openu,openr) the same text file using multiple IDL prompts. The different prompts usually read/write the file at different time, but there is a tiny chance that they read/write at the same time. Is there any keywords or routines that can test if other program is using the file?
>
>>
>
>>
>
>>
>
>> Ideally, I'd like to do something like this:
>
>>
>
>>
>
>>
>
>> test_if_someone_writing?
>
>>
>
>> yes: wait for 3 seconds and try again
>
>>
>
>> no: go ahead and read/write
>
>>
>
>>
>
>>
>
>> Thanks!
>
>
>
> There is nothing in IDL's file I/O library that will do this directly. You might consider using a semaphore around your openw and openr statements. See the docs for SEM_CREATE, SEM_LOCK, SEM_RELEASE, and SEM_DELETE. They're intended primarily to prevent conflicts and collisions on system resources, disk files included.
>
>
>
> Jim P.

Jim's suggestion is a good one. Another possibility is to create another copy of the file (file_copy), write all your data to it, and then use file_move to give it the correct name. That way you don't need to worry about writing new data while the file is still being read in another IDL process. You would probably need to put a catch (or on_ioerror?) to make sure the file_move didn't fail.

Cheers,
Chris
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: check if other routine is writing a text file
Next Topic: stregex fails to match underscore

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:19:51 PDT 2025

Total time taken to generate the page: 0.00412 seconds