I can do it with .txt files, that when something is happening it writes “ok”, and an other program reads it and do something if the .txt file has “ok” inside it. But, I would like to know if I can do with another way.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use a signal, e.g. USR1, but I don’t think you can raise signals in Python.
Instead of communicating via a file as you do now you can use a named pipe. A named pipe will provide some extra functionality, see last paragraph.
You open the pipe as an ordinary file and then write and read as you do now. You create the pipe by
mkfifo filename, can also be created in your python program. Two example programs for demo:Sender:
Receiver:
The sender opens a blocking pipe, so you will get an exception if the receiver closes the pipe, usually while terminating. The reader opens a non-blocking pipe so it will not hang while waiting for anything written by the sender. Combinations of blocking/non-blocking yield different responses when sender or receiver close one pipe end. You may want to open the write end non-blocking if there are any chance of pipe overflow (kbytes written, nothing read).