Browse Source

add: example pipe ... for socket replacement

micha 3 years ago
parent
commit
c65c92e892
1 changed files with 32 additions and 0 deletions
  1. 32 0
      lib/pipe.py

+ 32 - 0
lib/pipe.py

@@ -0,0 +1,32 @@
+import os, sys
+import random
+import time
+
+path = "/tmp/pipe"
+# pipe as socket replacement
+
+try:
+    try:
+        os.mkfifo(path)
+        while 1:
+            fifo = open(path, 'r')
+            x=fifo.read()
+            if x:
+                print(x)
+            time.sleep(0.3)
+    except OSError as e:
+        print( "EXC FIFO create", e)
+        i = 0
+        while 1:
+            x=random.randint(1000,9999)
+            print(i)
+            fifo = open(path, 'w')
+            fifo.write("{} {}\n".format(x,i))
+            fifo.flush()
+            fifo.close()
+            i+=1
+            time.sleep(1)
+
+except:
+    os.unlink(path)
+