Hi,
I'm having a little trouble when I read from a named pipe. I create a
pipe by
os.mkfifo('/tmp/mypipe')
and then open it for reading with
fin = open('/tmp/mypipe','r+')
(I don't use 'r' as that cause the open command to block). However when I
do from another terminal:
ls -l /tmp/mypipe
and then from my Python session do:
fin.readlines()
it just hangs and I have to Ctrl-C to get out. But when I do from a
terminal:
ls -l /tmp/mypipe ; cat < /tm/mypipe
I get the output of the ls command. Why does'nt Python read from the pipe
when some other program writes to it?
Thanks,
Rajarshi 4 7459
On Tue, 13 Jul 2004, Rajarshi Guha wrote: fin = open('/tmp/mypipe','r+')
(I don't use 'r' as that cause the open command to block).
It only blocks until a process connects to it for writing. 'r+' causes it
not to block because it causes 'fin' to be connected for both reading and
writing (probably not what you want). You should use 'r' as the mode.
ls -l /tmp/mypipe
You probably mean 'ls -l > /tmp/mypipe'. The command you have just lists
/tmp/mypipe; you need the redirection symbol to send the output to
/tmp/mypipe, otherwise it just ends up on the screen.
and then from my Python session do:
fin.readlines()
it just hangs and I have to Ctrl-C to get out.
This command will block until the writing process has closed the pipe.
Because you opened fin for both reading and writing, this command will
never return (it's basically waiting for itself to close).
But when I do from a terminal:
ls -l /tmp/mypipe ; cat < /tm/mypipe
I get the output of the ls command.
As above, this should be ls -l > /tmp/mypipe to work properly. This just
lists /tmp/mypipe directly to the screen. (It should probably block, too.)
Hope this helps.
In article <pa************ *************** *@presidency.co m>,
Rajarshi Guha <ra******@presi dency.com> wrote: I'm having a little trouble when I read from a named pipe. I create a pipe by
os.mkfifo('/tmp/mypipe')
and then open it for reading with
fin = open('/tmp/mypipe','r+')
(I don't use 'r' as that cause the open command to block). However when I do from another terminal:
ls -l /tmp/mypipe
and then from my Python session do:
fin.readlines()
it just hangs and I have to Ctrl-C to get out. But when I do from a terminal:
ls -l /tmp/mypipe ; cat < /tm/mypipe
I get the output of the ls command. Why does'nt Python read from the pipe when some other program writes to it?
Well, there may be a couple of issues here. The first is
that in order for anything to be read from a named pipe,
something has to be written to it. That's elementary, but
neither of your examples suggest that this is happening.
Once you're writing to it, you will find that readlines()
will work only when the writer closes its pipe file descriptor
(possibly by exiting), because readlines() can't return
until the entire "file" has been read.
Don't use a named pipe if an ordinary disk file would do.
Donn Cave, do**@u.washingt on.edu
> Don't use a named pipe if an ordinary disk file would do.
This may be a tad off topic, but in some ways it seems to
me that the converse is true. Discussion?
On Wed, 14 Jul 2004 17:57:42 -0700, Tobiah <to*********@rc sreg.com> wrote: Don't use a named pipe if an ordinary disk file would do.
This may be a tad off topic, but in some ways it seems to me that the converse is true. Discussion?
Files are both simpler and more powerful than named pipe: they don't
block, they don't necessarily have race conditions (on posix
filesystems), they can be locked, seeked, mmaped, compressed,
encrypted, ...
So, if a file does what you want, use a file. A named pipe is good for
the one thing it is good at: connecting _one_ reader and _one_ writer
in strict unidrectional synchrony when they aren't directly related in
the process tree, and when either one (or both) can't be modified to
use sockets instead. That's a niche for you.
--
John Lenton (jl*****@gmail. com) -- Random fortune:
bash: fortune: command not found This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Srijit Kumar Bhadra |
last post by:
Hello,
Here is an example of Multithreaded Pipe Server and Client using the
excellent ctypes library (Windows).
Reference - MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/multithreaded_pipe_server.asp
and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/named_pipe_client.asp
Best Regards,
|
by: richard |
last post by:
I have a simple test to pass information from a client to a server
using named pipe. what I really want is: when I type a line on the client,
the server will output the line immediately. but to my surprise, I always
have to terminate the client to get the server in action, i.e. prints out
what I typed.
anything I missed? I am compiling using gcc without any option.
thanks,
---RICH
|
by: Ken Allen |
last post by:
Is there any built-in facility for handling named pipes in C#/.Net, or must
one use unsafe code to access the WIN32 API directly?
There exists some code that uses named pipes heavily and there exists a need
for that code to send some information to a new .Net service I am writing.
It is a relatively simple matter for the existing code to use a named pipe
to send the data, but I can find no references to how I can create the named
pipe...
|
by: EricR |
last post by:
I am trying to use .NET to "tap into" a named pipe created by a non .NET 3rd
party application. Specifically, the application is a table loading utility.
It opens a named pipe and waits for input.
Does anybody know how I can write to the named pipe from a .NET program. I
have tried using the traditional file access methods, and it appears that
pipes have a problem with file streams. I have tried API calls, but since I
do not have the...
|
by: Nick |
last post by:
hi,all
I have a question about named pipe.
How does the pipe server know the client closed the connection?
We can refer the example for CreateNamedPipe() function in MSDN.
In block mode, once ConnectNamedPipe() returns, it means the client
called CreateFile(),
and after finish reading and writing, client call CloseHandle(), at
this point, how does the pipe server know the pipe has been closed? And
if client did not call CloseHandle(),...
| |
by: FB's .NET Dev PC |
last post by:
I am writing two services in VB.NET, one of which needs to send text strings
to the other. After reading, I
decided (perhaps incorrectly) that named pipes would be the best
interprocess communication method
for this task.
I set about creating, on the pipe's server side, a new thread which would
instantiate a blocking inbound message pipe, and the
client side which would write to that pipe when needed. Being on the same
PC, security is...
|
by: olaf.dietsche |
last post by:
Hi,
The system is Windows XP and DB2 v8.1.7.
I'm trying to load a text file via named pipe into a table.
I have two programs:
the first program creates the named pipe, waits for a client and
writes the text file into the named pipe.
the second program is doing the db2Load() call.
|
by: dgk |
last post by:
I trying to use a named pipe but can't figure out how to get the
callback to work:
Module Module1
Private ps As System.IO.Pipes.NamedPipeServerStream
Public Sub main()
Application.EnableVisualStyles()
Try
ps = New System.IO.Pipes.NamedPipeServerStream("Test")
ps.BeginWaitForConnection(AddressOf HandleConnection, "Test")
|
by: andrewb |
last post by:
Hi all,
Having some trouble using named pipes and Visual Basic .NET and would
appreciate and help you could offer.
Essentially I am trying to develop a simple client/server application
that exchanges text messages using named pipes. The internet resources
seem a bit scarce and the only Microsoft resource I can find is
http://support.microsoft.com/kb/871044.
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |