def view(request): if not(request.user.is_authenticated() or settings.DEBUG): raise PermissionDenied() if request.method == 'POST': handle_post(request) # want to redirect so that refresh works again. return HttpResponseRedirect(reverse('management')) daemon_status = 'running' if tqdaemon.status() else 'stopped' return render_to_response('management.html', {'settings': settings, 'daemon_status': daemon_status}, context_instance=RequestContext(request))
def ensure_daemon(): """Check to see if daemon is running, attempt to start it if not. Timing reported this at ~50 us if the daemon was already running; shouldn't be bad to keep in main path. If the daemon wasn't running waiting for it to start is a good thing. """ if not tqdaemon.status(): log.info("Attempting to start missing tqdaemon.") p = multiprocessing.Process(target=tqdaemon.daemonize) p.start() p.join(1) time.sleep(0.1)
def start_daemon(request): client.ensure_daemon() if tqdaemon.status(): messages.info(request, "Daemon started successfully.") else: messages.error(request, "Daemon failed to start.")