def run(self, *args, **options): """ Runs the server, using the autoreloader if needed """ use_reloader = options.get('use_reloader') if use_reloader: autoreload.main(self.inner_run, args, options) else: self.inner_run(*args, **options)
r = self._wsgi.render(request) request.responseHeaders.setRawHeaders( b'Cache-Control', [b'no-cache', b'no-store', b'must-revalidate']) request.responseHeaders.setRawHeaders(b'expires', [b'0']) return r # web-client files served from here base_resource = File('../client/dist') # api requests must go through /api base_resource.putChild('api', ServerResource(wsgi_app)) # downloadable files go here base_resource.putChild('file', File(config.SAVE_FOLDER)) site = Site(base_resource) # Start the threadpool now, shut it down when we're closing threadpool.start() reactor.addSystemEventTrigger('before', 'shutdown', threadpool.stop) endpoint = serverFromString(reactor, "tcp:port=" + str(config.PORT)) endpoint.listen(site) reactor.run() if __name__ == "__main__": autoreload.main(run_app_in_twisted)
# httpserver.serve(app, host='127.0.0.1', port='8080') def pyshell(): initstubs() from models import Album, Photo, Var, Page ### PUT CODE HERE # ... from tasks import update_photos update_photos() ### SHELL START! from wx.py.PyShell import main main(dict(globals(), **locals())) # @UnresolvedImport if __name__ == "__main__": # Respond to requests until process is killed import sys if "-sh" in sys.argv: pyshell() elif "-nr" in sys.argv: main() else: import autoreload autoreload.main(main)
# save a file to disk x = web.input(file={}) y = web.rawinput('both') if not x.file == {}: filepath= x.file.filename.replace('\\','/') # replaces the windows-style slashes with linux ones. filename = filepath.split('/')[-1] # splits the and chooses the last part (the filename with extension) filename = unicode(filename, "utf8") fout = open(os.path.join(root,filename),'wb') # creates the file where the uploaded file should be stored fout.write(x.file.file.read()) # writes the uploaded file to the newly created file. fout.close() elif x.has_key("directory"): print y.directory.filename,'----------------' # closes the file, upload complete. else :print '' return "<script>parent.location.reload()</script>" # start the application # it's adaptable to both uwsgi start & python start app = web.application(urls,globals()) application = app.wsgifunc() if __name__ == "__main__": # app.run() import socket ip = socket.gethostbyname(socket.gethostname()) print ip autoreload.main(app.run)
# -*- coding: utf-8 -*- """ core.autoreload-twistd ~~~~~~~~~~~~~~~~~~~~~~ Restarts HWIOS using the cherrypy autoreload script :copyright: Copyright 2011-2012 OS-Networks :license: LGPL, See LICENSE for details. """ import sys import autoreload try: import twisted.scripts.twistd as t autoreload.main(t.run) except ImportError: print "Failed to import twisted. Did you set PYTHONPATH yet?" print "Example: export PYTHONPATH=/usr/lib/python2.7/site-packages/"
self.selected = None def select_none(self): """Clear the selection.""" for obj in self: obj.selected = False self.selected = None def select(self, x, y): """Select the topmost object at the given x, y coordinates.""" self.select_none() for obj in reversed(self): if (x, y) in obj: obj.selected = True self.selected = obj break def main(): """Run main program loop.""" app = App() glutMainLoop() if __name__ == "__main__": if DEBUG: import autoreload autoreload.main(main) else: main()