-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# mule1.py: independent worker process | ||
# - a TCP server as an example | ||
|
||
import time | ||
import socketserver | ||
|
||
import logging | ||
log = logging.getLogger("mule") | ||
|
||
|
||
# example from https://docs.python.org/3/library/socketserver.html | ||
class MyTCPServer(socketserver.BaseRequestHandler): | ||
"""Simplest TCP server that echoes back the message.""" | ||
|
||
def handle(self): | ||
self.data = self.request.recv(1024).strip() | ||
log.info(f"got data: {self.data}") | ||
self.request.sendall(self.data.upper()+b"\n") | ||
|
||
|
||
def main(): | ||
"""Mule main function""" | ||
|
||
HOST = "0.0.0.0" | ||
PORT = 9999 | ||
|
||
log.info(f"example mule worker started, listening on TCP port {PORT}") | ||
|
||
# create a TCP server | ||
with socketserver.TCPServer((HOST, PORT), MyTCPServer) as server: | ||
server.serve_forever() | ||
|
||
# never reached in this example | ||
# if you return from a worker, uwsgi will automatically restart | ||
log.info("mule end") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
|