Python Forum
os.open and os.fdopen on windows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
os.open and os.fdopen on windows
#1
I think I've run into a problem with python locking files that were opened using open(). This happens one Windows 10

I am trying to pass information from a python application to a C# application via a shared file. When I open the file for writing in Python the C# application cannot open the file. When I close the file in Python the C# application can open and read the file. I know the problem is not flush() because I can see the size of the file change when the information is written (using the file browser) and I tried calling flush() after the write.

I think I can open an unlocked file using os.open() and os.fdopen() but I am having difficulty finding examples that run on Windows. I would be grateful for any links you can provide.
Reply
#2
Windows is different. You could use the win32pipe for named pipes, but the API is not Pythonic.
Here is an example: https://stackoverflow.com/questions/4854...amed-pipes

Instead, I would use zmq. This library is for IPC and does not require a dedicated server. You can use different patterns like PUB-SUB is one of them I used in my project to exchange information between different processes.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
I don't have a choice about how to do the communication. The C# application is not under my control.
Reply
#4
And what kind of file is it? A NamedPipe was my guess.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
Regular file.
Reply
#6
You could perhaps write a temporary file, then rename it now and then.

There is also this discussion in python.org.
« We can solve any problem by introducing an extra level of indirection »
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Open windows cmd prompt and run cmds with python Extra 3 3,236 Jul-14-2022, 06:07 AM
Last Post: Gribouillis
  Windows install does not create .exe, shortcut,etc to open hammer 4 3,131 May-05-2022, 12:33 PM
Last Post: hammer
  Is it possible to open windows and do screenshots with Python? cubangt 2 2,177 Jan-14-2022, 03:57 PM
Last Post: cubangt
  Open windows media player minimised TamP 1 2,891 Aug-02-2020, 08:40 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020