fifo

Python and FIFOs

不想你离开。 提交于 2019-12-07 03:40:13
问题 I was trying to understand FIFOs using Python under linux and I found a strange behavior i don't understand. The following is fifoserver.py import sys import time def readline(f): s = f.readline() while s == "": time.sleep(0.0001) s = f.readline() return s while True: f = open(sys.argv[1], "r") x = float(readline(f)) g = open(sys.argv[2], "w") g.write(str(x**2) + "\n") g.close() f.close() sys.stdout.write("Processed " + repr(x) + "\n") and this is fifoclient.py import sys import time def

Getting readline to block on a FIFO

孤街醉人 提交于 2019-12-07 01:02:26
问题 I create a fifo: mkfifo tofetch I run this python code: fetchlistfile = file("tofetch", "r") while 1: nextfetch = fetchlistfile.readline() print nextfetch It stalls on readline, as I would hope. I run: echo "test" > tofetch And my program doesn't stall anymore. It reads the line, and then continues looping forever. Why won't it stall again when there's no new data? I also tried looking on "not fetchlistfile.closed", I wouldn't mind reopening it after every write, but Python thinks the fifo is

linux上的进程通信学习笔记

大城市里の小女人 提交于 2019-12-07 00:17:42
参考资料 <<精通Linux C编程>> http://man7.org/linux/man-pages/man2/open.2.html https://www.cnblogs.com/52php/p/5840229.html 在 Android中的Handler的Native层研究 文章中研究一下一把Linux中的匿名管道的通信机制,今天这里Linux中的进程间通信补齐。 在Linux中,实现进程通信的方法包括管道(匿名管道和具名管道),消息队列,信号量,共享内存,套接口等。消息队列,信号量,共享内存统称为系统的(POSIX和System V)IPC,用于本地间的进程通信,套接口(socket)则运用于远程进程通信。 各个通信机制定义如下: 匿名管道(Pipe)和具名管道(named pipe):匿名管道用于具有亲缘关系进程间的通信,具名管道克服了管道没有名字的限制,因此除了具有匿名管道的功能外,还允许在无亲缘关系的进程中进行通信。 消息队列(Message):消息队列为消息的链接表,包括POSIX消息队列和System V消息队列。有足够权限的进程可以向队列中添加消息,被赋予读权限的进程则可以读取队列中的消息。 共享内存:是的多个进程可以访问同一块内存空间,是最快的可以IPC形式。是针对其他的通信机制运行效率较低而设计出来的。往往与其他通信机制,如信号量结合使用

Unix FIFO in go?

泪湿孤枕 提交于 2019-12-06 20:01:18
问题 Is there any way to create a unix FIFO with Go language? There is no Mkfifo , nor Mknod in os package, though I expected named FIFOs are largely used in posix OS's. In fact, there is a function for creating an unnamed FIFO (pipe), but no function for creating named pipes. Am I the only one who needs them? 回答1: In order to get it to work on Linux, I simply did a syscall.Mknod(fullPath, syscall.S_IFIFO|0666, 0) It seemed to do the trick. Here is a reference for the underlying mknod() call 回答2:

Linux kernel /proc FIFO/pipe

女生的网名这么多〃 提交于 2019-12-06 11:24:47
问题 I'm currently trying to create a kernel module that will produce data based on kernel events and push them to a file. After reading that this is bad (and I agree), I decided it would make more sense to have the data in a /proc file that a user program could pull from when necessary. However, this idea led to all sorts of problems, particularly when and how to clear out this file. So I thought... "why don't I make a named pipe in /proc and read from that?" I've got the general gist of setting

Node.js fs.open() hangs after trying to open more than 4 named pipes (FIFOs)

旧街凉风 提交于 2019-12-06 10:57:41
I have a node.js process that needs to read from multiple named pipes fed by different other processes as an IPC method. I realized after opening and creating read streams from more than four fifos, that fs seems to no longer be able to open fifos and just hangs there. It seems that this number is a bit low, considering that it is possible to open thousands of files concurrently without trouble (for instance by replacing mkfifo by touch in the following script). I tested with node.js v10.1.0 on MacOS 10.13 and with node.js v8.9.3 on Ubuntu 16.04 with the same result. The faulty script And a

a FIFO query in SQL Server

江枫思渺然 提交于 2019-12-06 10:43:08
I'm building a stock management app in c# with SQL server . I want to make a FIFO query from my table. I purchased same products in variable rate. After that I sold some of them. I want to query based in "First in first out" according to BatchDate column. So I want to get the available in stock products with PurchasePrice. Here is my table: ` CREATE TABLE InventoryLedgers ( BatchNo nvarchar(30), BatchDate datetime, ProductId int, StockIn decimal(18, 2), StockOut decimal(18, 2), PurchasePrice decimal(18, 2), SalesPrice decimal(18, 2) ); INSERT INTO InventoryLedgers (BatchNo,BatchDate ,ProductId

How to implement a FIFO queue that supports namespaces

折月煮酒 提交于 2019-12-06 09:47:36
问题 I'm using the following approach to handle a FIFO queue based on Google App Engine db.Model (see this question). from google.appengine.ext import db from google.appengine.ext import webapp from google.appengine.ext.webapp import run_wsgi_app class QueueItem(db.Model): created = db.DateTimeProperty(required=True, auto_now_add=True) data = db.BlobProperty(required=True) @staticmethod def push(data): """Add a new queue item.""" return QueueItem(data=data).put() @staticmethod def pop(): """Pop

Shifting 2D array Verilog

我的梦境 提交于 2019-12-06 03:17:47
问题 I dont know what doesnt work on the following code, but it wont synthesize: reg [7:0] FIFO [0:8]; always@(posedge clk) begin if(wr & !rd & !full) begin FIFO[0:8] <= {data_in, FIFO[1:8]}; end end I tried to index the FIFO other ways too, but nothing works. Found this topic on a Xilinx forum but I just cant figue out what he wanted to tell with that. Here is the link: http://forums.xilinx.com/t5/General-Technical-Discussion/2-dimensional-array-problem-in-Verilog/td-p/42368 thanks 回答1: You have

a text file circular buffer in python

折月煮酒 提交于 2019-12-06 00:34:52
问题 I need a python script implementing a circular buffer for rows in a text file limited to N rows like this: row 1 -> pop row 2 row 3 | | push -> row N What's the best solution? EDIT: This script should create and maintain the text file which only contains the latest N lines. Then it should pop the first line pushed in. Like a fifo buffer. 回答1: Try my recipe and sorry for italian usage: #!/usr/bin/env python # -*- coding: utf-8 -*- # # fifo(.py) # # Copyright 2011 Fabio Di Bernardini <fdb