Guest User

Untitled

a guest
Jul 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/usr/bin/python3
  2. def WebFunc(outfrompipe, intopipe):
  3. global thread
  4.  
  5. app = Flask(__name__)
  6. app.config['SECRET_KEY'] = 'secret!'
  7. socketio = SocketIO(app, async_mode=”eventlet”)
  8. thread = None
  9. thread_lock = Lock()
  10.  
  11. @app.route('/')
  12. def index():
  13. return render_template('index.html', async_mode=socketio.async_mode)
  14.  
  15. @socketio.on('my_event', namespace='/test')
  16. def test_msg(msg):
  17. # Receive a message from a web app
  18. print(“Received message”, msg)
  19. # Send this message to another process
  20. # THIS IS WHERE IT HANGS!!
  21. intopipe.send(msg)
  22.  
  23. socketio.run(app, debug=False, host='0.0.0.0')
  24.  
  25. #!/usr/bin/python3
  26. import webprocess as webproc
  27. import multiprocessing
  28. import time
  29.  
  30. if __name__ == '__main__':
  31.  
  32. multiprocessing.set_start_method('spawn')
  33. outfrompipe, intopipe = multiprocessing.Pipe()
  34.  
  35. wf = multiprocessing.Process(name=”WebProc”, target=webproc.WebFunc,
  36. args=(outfrompipe, intopipe))
  37. wf.start()
  38.  
  39. while True:
  40. message = outfrompipe.recv()
  41. print(message)
  42. time.sleep(1)
  43.  
  44. wf.join()
Add Comment
Please, Sign In to add comment