1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
17 #include "common/Thread.h"
18 #include "common/LogClient.h"
24 * Implement the pattern of calling serve() on a module in a thread,
25 * until shutdown() is called.
30 // Info about the module we're going to run
31 PyModuleRef py_module
;
34 // Populated by descendent class
35 PyObject
*pClassInstance
= nullptr;
39 class PyModuleRunnerThread
: public Thread
44 explicit PyModuleRunnerThread(PyModuleRunner
*mod_
)
47 void *entry() override
;
50 std::string thread_name
;
55 void log(int level
, const std::string
&record
);
57 const char *get_thread_name() const
59 return thread_name
.c_str();
63 const PyModuleRef
&py_module_
,
66 py_module(py_module_
),
70 // Shortened name for use as thread name, because thread names
71 // required to be <16 chars
72 thread_name
= py_module
->get_name().substr(0, 15);
74 ceph_assert(py_module
!= nullptr);
79 PyModuleRunnerThread thread
;
81 std::string
const &get_name() const { return py_module
->get_name(); }