Control stript which is runing in background.

jak nospam at please.ty
Fri Jan 1 05:11:47 EST 2021


Il 01/01/2021 04:14, 2QdxY4RzWzUUiLuE at potatochowder.com ha scritto:
> On 2021-01-01 at 03:43:43 +0100,
> Regarding "Re: Control stript which is runing in background.,"
> jak <nospam at please.ty> wrote:
> 
>> Il 01/01/2021 01:43, Cameron Simpson ha scritto:
>>> On 01Jan2021 01:21, jak <nospam at please.ty> wrote:
>>>> Il 01/01/2021 00:58, 2QdxY4RzWzUUiLuE at potatochowder.com ha scritto:
>>>>> Most of the time, I have several shells open, often with their own
>>>>> background jobs running.  Limiting write permission on the pipe to "me"
>>>>> wouldn't prevent concurrent access.
>>>>
>>>> This is true but there would be no difference if this happened through
>>>> a socket.
>>>
>>> Accessing a socket makes a distinct separate data connection - other
>>> openers do not conflict with it. That's the critical difference between
>>> a socket and a pipe in terms of functionality, and why sockets have a
>>> connect/accept step.
>>>
>>> Cheers,
>>> Cameron Simpson <cs at cskk.id.au>
>>>
>>
>> Maybe the fact that I'm not English and I don't know the language well
>> doesn't allow me to express myself clearly. Try it one more time:
>> The OP would like to give some command to a script that is running. How?
>> With a script that sends commands to it. One of the ways, as mentioned,
>> is by using a mini socket server. Given the needs of the OP and the fact
>> that sockets are a limited resource in a system, I took the liberty of
>> proposing a simple alternative: using a named pipe, also because, IMO,
>> sockets, in this case, are an overkill. with a few lines of code in a
>> thread in the running script they can allow it to receive commands:
>> #-----------------
>> import os, errno
>>
>> fnpipe = 'cmdpipe'
>>
>> try:
>>      os.mkfifo(fnpipe)
>> except OSError as e:
>>      if e.errno != errno.EEXIST:
>>          raise
>> while True:
>>      with open(fnpipe, 'rt', 1) as fifo:
>>          for line in fifo:
>>              print(line, ends='')
>> #-----------------
>>
>> Running the command:
>>
>> $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt >
>> cmdpipe
>>
>> the three texts do not mix. IMO, the OP should be enough. after that, I
>> know that a pipe is more like a queue than a soket and in this case a
>> socket, IMO, is wasted.
> 
> Only the OP knows for sure.  :-)   Does the server send data back to the
> client that made the request?  Are the requests (and the responses, if
> any) small enough to be sent/received atomically?  *If* the answers are
> no and yes, then you're right, a named pipe would be good enough.  If
> not, then a socket *might* be better.  Until the OP clarifies, we can't
> tell.
> 
>> greetings, hoping to have been clearer than before.
> 
> I think you were clear enough before, but you may not have considered
> things the OP did not specify.  One of the hardest parts of software
> development is understanding and specifying the actual problem to be
> solved.  I've never done that in a second language (I'm nowhere near
> fluent in anything other than English); I can only imagine the extra
> layers of complexity.
> 

This is the OP's initial request:

> Hi. 
> I would like to make something like this:
> A python script would run headlessly in the background.
> I would like to control the script from the command line using other python scripts or from the python shell.
> From time to time I would ask the main script to create a popup window with an image or a plot.
> What would be the proper way to approach it. How to make communication between two scripts?
> Thank you.
> Petro.

I have suggested an alternative way for his necessity.
It will be up to him to decide which one he should adopt. That way he
has a choice, at least.
I don't know where you work. I know, however, that in these zones, if
you do more than necessary wasting their time, they will kick you away.


More information about the Python-list mailing list