pipe

Passing a Pipe/Connection as context arg to multiprocessing Pool.apply_async()

人走茶凉 提交于 2019-12-24 04:00:37
问题 I want to use pipes to talk to the process instances in my pool, but I'm getting an error: Let __p be an instance of Pool(): (master_pipe, worker_pipe) = Pipe() self.__p.apply_async(_worker_task, (handler_info, context_info, worker_pipe)) When I execute this, I get the following error [for every instance, obviously]: File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 376, in get task = get() File "/System/Library/Frameworks/Python

Pipe multiple files to one response

故事扮演 提交于 2019-12-24 02:57:39
问题 I'm trying to write two files and some more text to a response. The code below does however only return the first file and the "Thats all!" text. var http = require('http'), util = require('util'), fs = require('fs'); server = http.createServer(function(req, res){ var stream = fs.createReadStream('one.html'), stream2 = fs.createReadStream('two.html'); stream.on('end', function(){ stream2.pipe(res, { end:false}); }); stream2.on('end', function(){ res.end("Thats all!"); }); res.writeHead(200, {

Append output of one command to the output of another in a single command

╄→尐↘猪︶ㄣ 提交于 2019-12-24 02:25:18
问题 Is there a way to append the stdout output of one command to another's and pipe the combined output to another command? I used to use the following approach(taking ack-grep as an example) # List all python, js files in different directories ack-grep -f --py apps/ > temp ack-grep -f --js -f media/js >> temp cat temp | xargs somecommand Is there a way to do this in a single command? 回答1: Just run the two ack-grep commands as a compound command; then pipe the results of the compund command. The

how to filter the list using pipes in angular 2

家住魔仙堡 提交于 2019-12-24 01:47:19
问题 could you please tell me how to filter the list using pipes in angular 2 https://stackblitz.com/edit/angular-qvtqeu?file=src%2Fapp%2Fapp.component.html I tried like this <ul class="user-list | filterlist:userenter"> <li *ngFor="let user of users" class="user-list__item"> Filter import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'filterlist' }) export class FilterlistPipe implements PipeTransform { transform(value: any, args?: any): any { return value.filter( item => item.first

Piping the output of one command as input to another command [closed]

淺唱寂寞╮ 提交于 2019-12-24 01:17:57
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I know at least the basics of piping. However, I don't understand how to implement this task in in C using C pipes. I don't know how to take the output of one program as an input to another program and so on. Eg:

Pipe: Bad file descriptors

南楼画角 提交于 2019-12-24 00:44:02
问题 I know this kind of posts have been asked previously, but their level are clearly higher than mind, I still don't get it after reading their post, so I decide to post this question again from here. I am learning multi-processes communication using pipe, I have confronted to this error called Bad file descriptors, I don't understand why I am having this error in my code. #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> #include <string.h> #define SIZE 50 struct

Pipe file contents in g++ to compile

社会主义新天地 提交于 2019-12-23 23:38:33
问题 Is it possible to pipe the contents of a file into g++ to compile a program? I want to do this because I want to use a file from a database rather than a physical file on a disk. The file contents can be easily retrieved via an API I have made. For instance, I would like to do something like: g++ contents_of_file -o executable Thanks a lot. Sam. 回答1: Yes, you can pipe to gcc if you specify the language using the -x option; echo "int main(){}" | gcc -Wall -o testbinary -xc++ - 回答2: more fun:

C Shell: Redirection and piping working, but not a combination of input and output redirection with 1 or more pipes

梦想与她 提交于 2019-12-23 23:04:52
问题 My C shell can successfully handle redirection (e.g. ls -al > output.txt, ./pre < input1.txt, etc.) and multiple pipes (i.e. cmd1 | cmd 2 | cmd 3). However, my code is not working when I try to do input and output redirection together with a pipe, such as ./pre < input.txt | ./sort > output.txt. No output file is ever made, although the ./pre does successfully execute. pre is an executable that prints names with GPAs over 3.0 sort is an executable that alphabetizes a list of names input.txt

python多进程-----multiprocessing包

雨燕双飞 提交于 2019-12-23 21:47:20
multiprocessing并非是python的一个模块,而是python中多进程管理的一个包,在学习的时候可以与threading这个模块作类比,正如我们在上一篇转载的文章中所提,python的多线程并不能做到真正的并行处理,只能完成相对的并发处理,那么我们需要的就是python的多进程来完成并行处理,把所有的cpu资源都利用起来。multiprocessing的很大一部分与threading使用同一套API,只不过换到了多进程的环境。这里面要注意,对于多进程来说,win32平台和unix平台差别很大,我们最好在linux上完成实现。 使用这些共享API时,我们应该注意以下问题(目前这是我能想到的,以后遇到再扩充): 1、对join的处理 根据Unix环境高级编程中对进程控制一章的描述,当某个进程fork一个子进程后,该进程必须要调用wait等待子进程结束发送的sigchld信号,对子进程进行资源回收等相关工作,否则,子进程会成为僵死进程,被init收养。所以,在multiprocessing.Process实例化一个对象之后,该对象有必要调用join方法,因为在join方法中完成了对底层wait的处理,源码如下: def join(self, timeout=None): ''' Wait until child process terminates ''' assert

Why does my Java code execute bash command incorrectly?

别说谁变了你拦得住时间么 提交于 2019-12-23 21:24:06
问题 I am trying to make my Java program interact with Linux bash but something goes wrong. I have a simple executable prog that reads the one integer from stdin and outputs its square. Executing echo 5 | ./prog from bash itself prints correct answer 25 in stdout but running import java.io.*; public class Main { public static void main(String[] args) throws InterruptedException, IOException { Runtime run = Runtime.getRuntime(); Process proc = run.exec("echo 5 | ./prog"); proc.waitFor();