#!/usr/bin/env python3
import asyncio
+import dummy_killer
import tornado.ioloop
import tornado.web
import tornado.httpserver
# Write the PID to the specified PID file, if provided
if args.pidfile:
- with open(args.pidfile, "w") as f:
- f.write(str(os.getpid()))
+ dummy_killer.write_pid(args.pidfile)
# Start the server
server.bind(args.port, args.bind)
await asyncio.Event().wait()
if __name__ == "__main__":
- asyncio.run(main())
\ No newline at end of file
+ asyncio.run(main())
import signal
import os
import atexit
+import tempfile
def setup_killer(server, method = None):
def default_method():
def write_pid(path):
- with open(path, 'w+') as f:
+ with tempfile.NamedTemporaryFile(mode='w', delete=False) as f:
f.write(str(os.getpid()))
f.close()
+ os.rename(f.name, path)
def cleanup():
os.remove(path)