python - Opening named pipe in one module, reading in the other -


i'm hot on trail of figuring out 1 of projects, hung on 1 issue:

i'm using fifo operation send 'signal' (simple t/f) 1 module another. 1 module opens fifo write it, , other opens fifo read it. goal here have reading module read , display writing module receives command so. writing module opens fifo, reading module doesn't seem so.

is i'm trying possible? i'm trying spin both operations in _threads in order keep multiple processes going in each module. note both modules in classes didn't include sake of brevity (explaining 'self').

original sending module

def pipe_relay(self):     fifo = 'pipe_relay'     thread_num = num      try:         os.mkfifo(fifo)     except oserror oe:         if oe.errno != errno.eexist:             raise      while self.relay_switch:         print("opening fifo...")         open(fifo) fifo:             print("fifo opened")             while self.relay_switch:                 data = fifo.write(signal)                 if len(data) == 0:                     print("writer closed")                     break                 print('write: "{0}"'.format(data)) 

updated sending module

i realized didn't want writing fifo continuously data threw @ it, removed while() statement. now, doesn't seem though fifo open @ all...


def pipe_relay(self, num, signal):     fifo = 'pipe_relay'     thread_num = num      try:         os.mkfifo(fifo)     except oserror oe:         if oe.errno != errno.eexist:             raise      print("opening fifo...")      # not proceed past point      open(fifo, mode = 'w') fifo:         print("fifo opened")         data = fifo.write(signal)         if len(data) == 0:             print("writer closed")         print('write: "{0}"'.format(data))         fifo.close() 

receiving module

def pipe_receive(self):     fifo = 'pipe_relay'      try:         os.mkfifo(fifo)     except oserror oe:         if oe.errno != errno.eexist:             raise         # module proceeds here, no further      open(fifo) fifo:         print("fifo opened (receiver)")         while true:             data = fifo.read()             if len(data) == 0:                 print("writer closed")                 break             print('read signal: "{0}"'.format(data))             self.display['text'] = data     print("this in 'pipe_receieve'") 

edit

running ubuntu 17.04. project written python 3.5 interpreter.

i'm bit surprised code doesn't raise exception. in writer, regular open(filo), without specifying mode parameter. according the documentation, mode defaults r (read-only), expect fifo.write(signal) raise ioerror. exceptions being caught somewhere?

either way, should add mode="w" writer-side open fifo writing.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -