Panda3D
pythonThread.h
1 // Filename: pythonThread.h
2 // Created by: drose (13Apr07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PYTHONTHREAD_H
16 #define PYTHONTHREAD_H
17 
18 #include "pandabase.h"
19 
20 #include "thread.h"
21 
22 #ifdef HAVE_PYTHON
23 ////////////////////////////////////////////////////////////////////
24 // Class : PythonThread
25 // Description : This class is exposed to Python to allow creation of
26 // a Panda thread from the Python level. It will spawn
27 // a thread that executes an arbitrary Python functor.
28 ////////////////////////////////////////////////////////////////////
29 class EXPCL_PANDA_PIPELINE PythonThread : public Thread {
30 PUBLISHED:
31  PythonThread(PyObject *function, PyObject *args,
32  const string &name, const string &sync_name);
33  virtual ~PythonThread();
34 
35  BLOCKING PyObject *join();
36 
37 protected:
38  virtual void thread_main();
39 
40 private:
41  PyObject *_function;
42  PyObject *_args;
43  PyObject *_result;
44 
45 public:
46  static TypeHandle get_class_type() {
47  return _type_handle;
48  }
49  static void init_type() {
50  Thread::init_type();
51  register_type(_type_handle, "PythonThread",
52  Thread::get_class_type());
53  }
54  virtual TypeHandle get_type() const {
55  return get_class_type();
56  }
57  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
58 
59 private:
60  static TypeHandle _type_handle;
61 };
62 #endif // HAVE_PYTHON
63 
64 #endif
65 
void join()
Blocks the calling process until the thread terminates.
Definition: thread.I:298
A thread; that is, a lightweight process.
Definition: thread.h:51
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85