English 中文(简体)
保持一个开放的进程,并在沙尔与它沟通
原标题:Keeping a process open and communicating with it in Python
  • 时间:2011-06-09 16:58:11
  •  标签:
  • python

我正在用假冒的文字做一些改动。 我这样做了。

python exec.py pollutants.in.1输出.out.1

此处为编号。

既然如此,它就要求使用变数文档中的数值进行迫害,然后将可执行的产出列入产出档案。 不幸的是,我看到的是,再一次又一次要求起诉,需要更多的时间。

In stead what I want to do is start the executable once and then send the variables to the executable using the same syntax, i.e. python exec.py pollutants.in.1输出.out.1.

我需要保留这一辛迪加,因为变数文件是外部产生的。 我对此没有控制,但一旦产生,我就需要利用可起诉的手段来制作产出文件,然后需要按规定格式加以分类。

EDIT:我试图以简化的方式代表我所做的工作,因为这是一个庞大的法典。

import sys
import os
import parseinput
import parseoutput

s1=sys.argv[1];s2=sys.argv[2]

op=open(s1, r );inp=op.readlines();op.close()
variableswrite=parseinput.parseinput(inp)
op=open( pass.dat , w );op.write(variableswrite);op.close()

os.sytem( execute < pass.dat )

op=open( executeout.dat , r );out=op.readlines();op.close()
outwrite=parseoutput.parseoutput(out)
op=open(s2, w );op.write(outwrite);op.close()

这是显示我所做工作的非常粗略的方法。 如果是代码外壳,则每当我使用python exec.py变数进行操作时,我便会收到一份产出文件,使用可执行的文件,以获得产出档案。

相反,如果我能够保持可执行的可执行性,并且仍然做假装的外壳变数。 1 结果。 1 文字将淡化投入文件,然后将其送交公开的可执行文件,从而产生产出,那么我的工作就会更快、高效。

问题回答

是否有办法扩大<代码>exec.py,以吸收任何数量的投入/产出文档名称。

如果是的话,援引将考虑:

python exec.py variables.in.1 output.out.1 ... variables.in.N output.out.N

现在,你有1000个这样的奶牛。 您可将这一范围分为20组,由50个奶制品组成(例如)。 并援引20次(同时)与不同群体的文字:

python exec.py variables.in.1 output.out.1 ... variables.in.50 output.out.50
python exec.py variables.in.51 output.out.51 ... variables.in.100 output.out.100
...
python exec.py variables.in.951 output.out.951 ... variables.in.1000 output.out.1000

你们想要的是

(1) 建立一个管理所有时间的 da程序

2) 监测档案或文件夹为理由

3) 用于探测新收到的档案

http://pyinotification.sourceforge.net/

4) 每次抽取时间都发出信号,通过称之为方法,在你的mon中引发转变

如果 s子拥有“平线”指挥,则你不能保持同声,因为这将永远恢复口译。

What you need here is in the "subprocess" module, which makes it simple to start processes and connect their input and output pipes

避免在单独进程中阻碍投入和产出。 你们可以通过“s.fork”这样做:

import os
import subprocess
execute = subprocess.Popen(
     execute ,
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE
)
if os.fork():
    #feed data into the input
    while True:
        input = ...
        execute.stdin.write(input)
else:
    outGenerator=Out
    #do something with the output
    for outline in execute.stdout:
        print outline

或者,你可将投入和产出代码分成两个文档,然后使用“main”等内容:

import os
import subprocess
generateInput = subprocess.Popen(
    [ python , generateInput.py ],
    stdout=subprocess.PIPE
)
execute = subprocess.Popen(
     execute ,
    stdin=generateInput.stdout,
    stdout=subprocess.PIPE
)
generateOutput = subprocess.Popen(
    [ python , generateOutput.py ],
    stdin=execute.stdout
)
execute.communicate()

which is just the long way of saying

python generateInput.py | execute | python gnerateOutput.py




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签