processtitle 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- processtitle-0.1.0/Acknowledgments.md +101 -0
- processtitle-0.1.0/LICENSE +29 -0
- processtitle-0.1.0/MANIFEST.in +2 -0
- processtitle-0.1.0/PKG-INFO +241 -0
- processtitle-0.1.0/README.md +205 -0
- processtitle-0.1.0/pyproject.toml +64 -0
- processtitle-0.1.0/setup.cfg +4 -0
- processtitle-0.1.0/setup.py +48 -0
- processtitle-0.1.0/src/cpp/bsd.h +24 -0
- processtitle-0.1.0/src/cpp/clobber.cpp +191 -0
- processtitle-0.1.0/src/cpp/clobber.h +20 -0
- processtitle-0.1.0/src/cpp/common.h +116 -0
- processtitle-0.1.0/src/cpp/darwin.cpp +176 -0
- processtitle-0.1.0/src/cpp/darwin.h +16 -0
- processtitle-0.1.0/src/cpp/external/intrusive_shared_ptr/apple_cf_ptr.h +46 -0
- processtitle-0.1.0/src/cpp/external/intrusive_shared_ptr/common.h +94 -0
- processtitle-0.1.0/src/cpp/external/intrusive_shared_ptr/intrusive_shared_ptr.h +576 -0
- processtitle-0.1.0/src/cpp/external/intrusive_shared_ptr/python_ptr.h +45 -0
- processtitle-0.1.0/src/cpp/external/pylib/arguments.h +397 -0
- processtitle-0.1.0/src/cpp/external/pylib/errors.h +31 -0
- processtitle-0.1.0/src/cpp/external/pylib/locking.h +100 -0
- processtitle-0.1.0/src/cpp/external/pylib/marshalling.h +381 -0
- processtitle-0.1.0/src/cpp/external/pylib/method.h +43 -0
- processtitle-0.1.0/src/cpp/external/pylib/util.h +82 -0
- processtitle-0.1.0/src/cpp/linux.cpp +247 -0
- processtitle-0.1.0/src/cpp/linux.h +16 -0
- processtitle-0.1.0/src/cpp/logger.h +54 -0
- processtitle-0.1.0/src/cpp/main.cpp +230 -0
- processtitle-0.1.0/src/cpp/pch.h +101 -0
- processtitle-0.1.0/src/cpp/solaris.cpp +49 -0
- processtitle-0.1.0/src/cpp/solaris.h +16 -0
- processtitle-0.1.0/src/cpp/win.cpp +135 -0
- processtitle-0.1.0/src/cpp/win.h +16 -0
- processtitle-0.1.0/src/extension.cpp +22 -0
- processtitle-0.1.0/src/processtitle/__init__.py +22 -0
- processtitle-0.1.0/src/processtitle/_processtitle.pyi +46 -0
- processtitle-0.1.0/src/processtitle/py.typed +0 -0
- processtitle-0.1.0/src/processtitle.egg-info/PKG-INFO +241 -0
- processtitle-0.1.0/src/processtitle.egg-info/SOURCES.txt +39 -0
- processtitle-0.1.0/src/processtitle.egg-info/dependency_links.txt +1 -0
- processtitle-0.1.0/src/processtitle.egg-info/top_level.txt +2 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Acknowledgements
|
|
2
|
+
|
|
3
|
+
**processtitle** contains code derived from the open source software listed below.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## [intrusive_shared_ptr](https://github.com/gershnik/intrusive_shared_ptr)
|
|
7
|
+
|
|
8
|
+
Distributed under MIT License
|
|
9
|
+
|
|
10
|
+
----
|
|
11
|
+
```
|
|
12
|
+
MIT License
|
|
13
|
+
|
|
14
|
+
Copyright (c) 2004 Eugene Gershnik
|
|
15
|
+
|
|
16
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
in the Software without restriction, including without limitation the rights
|
|
19
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
furnished to do so, subject to the following conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be included in all
|
|
24
|
+
copies or substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
SOFTWARE.
|
|
33
|
+
```
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## [libbsd setproctitle](https://gitlab.freedesktop.org/libbsd/libbsd/-/blob/main/src/setproctitle.c)
|
|
37
|
+
|
|
38
|
+
Distributed under MIT License
|
|
39
|
+
|
|
40
|
+
----
|
|
41
|
+
```
|
|
42
|
+
Copyright © 2010 William Ahern
|
|
43
|
+
Copyright © 2012 Guillem Jover <guillem@hadrons.org>
|
|
44
|
+
|
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
46
|
+
copy of this software and associated documentation files (the
|
|
47
|
+
"Software"), to deal in the Software without restriction, including
|
|
48
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
49
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
50
|
+
persons to whom the Software is furnished to do so, subject to the
|
|
51
|
+
following conditions:
|
|
52
|
+
|
|
53
|
+
The above copyright notice and this permission notice shall be included
|
|
54
|
+
in all copies or substantial portions of the Software.
|
|
55
|
+
|
|
56
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
57
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
58
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
59
|
+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
60
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
61
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
62
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
63
|
+
```
|
|
64
|
+
----
|
|
65
|
+
|
|
66
|
+
## [py-setproctitle](https://github.com/dvarrazzo/py-setproctitle)
|
|
67
|
+
|
|
68
|
+
Distributed under BSD 3-Clause License
|
|
69
|
+
|
|
70
|
+
----
|
|
71
|
+
```
|
|
72
|
+
BSD 3-Clause License
|
|
73
|
+
|
|
74
|
+
Copyright (c) 2009, Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
|
75
|
+
|
|
76
|
+
Redistribution and use in source and binary forms, with or without
|
|
77
|
+
modification, are permitted provided that the following conditions are met:
|
|
78
|
+
|
|
79
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
80
|
+
list of conditions and the following disclaimer.
|
|
81
|
+
|
|
82
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
83
|
+
this list of conditions and the following disclaimer in the documentation
|
|
84
|
+
and/or other materials provided with the distribution.
|
|
85
|
+
|
|
86
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
87
|
+
contributors may be used to endorse or promote products derived from
|
|
88
|
+
this software without specific prior written permission.
|
|
89
|
+
|
|
90
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
91
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
92
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
93
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
94
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
95
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
96
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
97
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
98
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
99
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
100
|
+
```
|
|
101
|
+
----
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Eugene Gershnik
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: processtitle
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Customize process "title" as reported by ps and similar tools
|
|
5
|
+
Author-email: Eugene Gershnik <gershnik@hotmail.com>
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Project-URL: Homepage, https://github.com/gershnik/processtitle
|
|
8
|
+
Project-URL: Documentation, https://github.com/gershnik/processtitle
|
|
9
|
+
Project-URL: Issues, https://github.com/gershnik/processtitle/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/gershnik/processtitle/blob/master/CHANGELOG.md
|
|
11
|
+
Keywords: setproctitle,proctitle,process title,process name
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
16
|
+
Classifier: Operating System :: POSIX :: BSD :: FreeBSD
|
|
17
|
+
Classifier: Operating System :: POSIX :: BSD :: NetBSD
|
|
18
|
+
Classifier: Operating System :: POSIX :: BSD :: OpenBSD
|
|
19
|
+
Classifier: Operating System :: POSIX :: SunOS/Solaris
|
|
20
|
+
Classifier: Intended Audience :: Developers
|
|
21
|
+
Classifier: Topic :: Software Development
|
|
22
|
+
Classifier: Programming Language :: C++
|
|
23
|
+
Classifier: Programming Language :: Python
|
|
24
|
+
Classifier: Programming Language :: Python :: 3
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
30
|
+
Classifier: Typing :: Typed
|
|
31
|
+
Requires-Python: >=3.10
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
License-File: Acknowledgments.md
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# processtitle
|
|
38
|
+
|
|
39
|
+
This Python extension module allows you to customize process "title" as reported by `ps`, `top`, Activity Monitor,
|
|
40
|
+
Task Manager and similar tools.
|
|
41
|
+
|
|
42
|
+
It is similar to the well known [py-setproctitle](https://github.com/dvarrazzo/py-setproctitle) module but,
|
|
43
|
+
not being constrained by backward compatibility, does things a bit differently and, hopefully, makes things more convenient
|
|
44
|
+
for a user. (If you are already familiar with `py-setproctitle` make sure to read [differences from py-setproctitle](#differences-from-py-setproctitle) section.)
|
|
45
|
+
|
|
46
|
+
Modifying process title is useful in many cases. When you have many Python scripts, or, worse, many instances of the
|
|
47
|
+
same Python script running on your system it is very hard to understand which one is which, if all you see in your process list
|
|
48
|
+
is "Python" or "python3 same-script". Using this module allows your script to specify _what it is for_ or _what it is doing_
|
|
49
|
+
to be shown in the process list instead.
|
|
50
|
+
|
|
51
|
+
<!-- TOC depthfrom:2 -->
|
|
52
|
+
|
|
53
|
+
- [Platform support](#platform-support)
|
|
54
|
+
- [Requirements](#requirements)
|
|
55
|
+
- [Installing](#installing)
|
|
56
|
+
- [Usage](#usage)
|
|
57
|
+
- [Thread and other safety](#thread-and-other-safety)
|
|
58
|
+
- [Differences from py-setproctitle](#differences-from-py-setproctitle)
|
|
59
|
+
- [Platform details](#platform-details)
|
|
60
|
+
- [Linux](#linux)
|
|
61
|
+
- [macOS](#macos)
|
|
62
|
+
- [Windows](#windows)
|
|
63
|
+
- [BSDs](#bsds)
|
|
64
|
+
- [Illumos](#illumos)
|
|
65
|
+
|
|
66
|
+
<!-- /TOC -->
|
|
67
|
+
|
|
68
|
+
## Platform support
|
|
69
|
+
|
|
70
|
+
The module will happily _run_ and do nothing on any [compatible system](#requirements) but the ones where it
|
|
71
|
+
actually _works_ (i.e. changes the process title) are: Linux, macOS, Windows, {Free|Net|Open}BSD and Illumos. See
|
|
72
|
+
[platform details](#platform-details) below for more information about each platform.
|
|
73
|
+
|
|
74
|
+
In all cases only reasonably recent versions of each platform are supported. No attempt is made to work
|
|
75
|
+
on ancient Linux kernels, Windows XP etc. etc. If you are stuck with a very old system your best bet is
|
|
76
|
+
[py-setproctitle](https://github.com/dvarrazzo/py-setproctitle).
|
|
77
|
+
|
|
78
|
+
## Requirements
|
|
79
|
+
|
|
80
|
+
* Python >= 3.10 capable of loading native extensions
|
|
81
|
+
* If your platform doesn't have a binary wheel available, you will need:
|
|
82
|
+
* A C++ compiler capable of compiling C++20 (GCC 10.2 or above and CLang 13 or above are known to work)
|
|
83
|
+
* Python development libraries available (like `python3-dev` package in most Linux distributions)
|
|
84
|
+
|
|
85
|
+
## Installing
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install processtitle
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Usage
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import processtitle
|
|
95
|
+
|
|
96
|
+
processtitle.prepare(...optional config params...)
|
|
97
|
+
|
|
98
|
+
if not processtitle.set_to("my fancy process"):
|
|
99
|
+
print("ooops, process title couldn't be set")
|
|
100
|
+
else:
|
|
101
|
+
print(f"last set process title is {processtitle.last_set()}")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The `processtitle.prepare` currently has the following keyword-only optional parameters defined:
|
|
105
|
+
|
|
106
|
+
`fork_safe_only: bool = False`
|
|
107
|
+
: use only such external libraries and/or APIs that
|
|
108
|
+
are safe if your process later performs a `fork` **without** `exec`.
|
|
109
|
+
Currently this is only relevant on macOS where APIs needed to update title in Activity Monitor
|
|
110
|
+
are **not** fork-safe and will cause crashes if used together with `fork` without `exec`.
|
|
111
|
+
|
|
112
|
+
If you wish to enable debug output from this module you can use standard `logging` machinery:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
import logging
|
|
116
|
+
|
|
117
|
+
logging.basicConfig(...)
|
|
118
|
+
logging.getLogger("processtitle").setLevel(logging.DEBUG)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Alternatively, you can use `py-setproctitle` compatible method by setting `SPT_DEBUG` environment variable
|
|
122
|
+
to a non-empty value (which is not "0"). For example:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
SPT_DEBUG=1 your_script_that_uses_processtitle
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Thread and other safety
|
|
129
|
+
|
|
130
|
+
`processtitle` _itself_ is thread-safe - all its operations are protected by a mutex. However,
|
|
131
|
+
_the effects_ of changing process title are not. On every platform, changing the title modifies
|
|
132
|
+
some globals process information. If this information is accessed by another thread at the same
|
|
133
|
+
time Bad Things Will Happen. Therefore, it is advisable to only change the title before other
|
|
134
|
+
threads are running or when you are absolutely sure they are suspended.
|
|
135
|
+
|
|
136
|
+
On some platforms, `processtitle` modifies pointers visible to native code (for example `argv[1]...` and
|
|
137
|
+
`environ` on many Unix systems). It never deallocates the memory pointed by these so any native code that
|
|
138
|
+
uses cached values of such pointer should be safe. Python's `sys.argv` and `os.environ` should be
|
|
139
|
+
completely unaffected by any of these manipulations.
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
## Differences from py-setproctitle
|
|
143
|
+
|
|
144
|
+
The most notable difference between `processtitle` and `py-setproctitle` is that this library requires you
|
|
145
|
+
to call `processtitle.prepare()` before setting the process title. Absolutely nothing is done prior to `prepare` -
|
|
146
|
+
just importing the module has no side effects. The `prepare()` method arguments allow you to customize library
|
|
147
|
+
behavior on platforms where multiple incompatible behaviors are possible. Currently this affects only macOS
|
|
148
|
+
(see [macOS details](#macos) below) but in the future might be extended to other platforms.
|
|
149
|
+
|
|
150
|
+
In addition:
|
|
151
|
+
|
|
152
|
+
* There is **no** requirement to import `processtitle` as early as possible. It does
|
|
153
|
+
not rely on Python interpreter state which may be changed by other libraries
|
|
154
|
+
* There is no general "get process title" call (instead you can query the last title _you set_ via `last_set()`).
|
|
155
|
+
This is because querying the original title might not be possible on some platforms.
|
|
156
|
+
* Currently there are no "set/get _thread_ title" calls. If there is any interest, they may be added in the future.
|
|
157
|
+
* `processtitle` supports Windows. At the time of this writing `py-setproctitle` does not.
|
|
158
|
+
* Wherever possible `processtitle` avoids tinkering with `argv` and relies on other safer, documented or
|
|
159
|
+
semi-documented methods.
|
|
160
|
+
* `processtitle` uses standard Python `logging` module to produce diagnostic output rather than just printing to
|
|
161
|
+
`stdout`. (For compatibility, `SPT_DEBUG` environment variable is also supported - it simply sets the default
|
|
162
|
+
logging level for this module to `logging.DEBUG`)
|
|
163
|
+
* `processtitle` is written in C++, not C, so it requires a reasonably modern C++ compiler when binary wheels
|
|
164
|
+
are not available.
|
|
165
|
+
* `processtitle` does not support old or no longer maintained operating systems like AIX, HP-UX etc.
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
## Platform details
|
|
169
|
+
|
|
170
|
+
### Linux
|
|
171
|
+
|
|
172
|
+
On Linux you will be able to see the process title in the output of `ps` or `top` commands, as well, as with any other
|
|
173
|
+
tool that displays process info. Note that on some Linux variants (e.g. Alpine) the title might be prefixed or suffixed
|
|
174
|
+
by the original process executable name. For example: `{python3} your title`.
|
|
175
|
+
|
|
176
|
+
To change the title, `processtitle` uses the following methods:
|
|
177
|
+
* [PR_SET_MM](https://www.man7.org/linux/man-pages/man2/PR_SET_MM.2const.html) call, if available and works.
|
|
178
|
+
* Otherwise [PR_SET_NAME](https://www.man7.org/linux/man-pages/man2/PR_SET_NAME.2const.html)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
### macOS
|
|
182
|
+
|
|
183
|
+
On macOS there are 2 independent places where process title is shown: `ps`, `top` and similar commands and
|
|
184
|
+
Activity Monitor. They take information from completely different places and modifying one doesn't modify the
|
|
185
|
+
other. Unfortunately, the API required to change the title for Activity Monitor **cannot be used if your process
|
|
186
|
+
later fork()-s without exec()**. If used in such a process, the forked process will most likely crash randomly and
|
|
187
|
+
unpredictably. Note that some popular libraries such as `gunicorn` may use fork() internally.
|
|
188
|
+
|
|
189
|
+
> [!IMPORTANT]
|
|
190
|
+
> Using fork without exec in Python on macOS (or any other platform) is, in general, dangerous because you rarely know
|
|
191
|
+
> for sure whether the libraries your code depends upon are fork-safe. This is why `multiprocessing` library
|
|
192
|
+
> [avoids fork by default](https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods)
|
|
193
|
+
> on macOS and, recently, on all platforms.
|
|
194
|
+
|
|
195
|
+
Because of this issue, if you must use fork() on macOS you have two options:
|
|
196
|
+
|
|
197
|
+
1. Pass `fork_safe_only=True` argument to `processtitle.prepare()` in the parent process. Doing so will prevent
|
|
198
|
+
use of any non-fork-safe APIs but will also preclude customized process title from being shown in Activity Monitor.
|
|
199
|
+
|
|
200
|
+
2. Alternatively, if feasible, call `processtitle.prepare()` **after** the last `fork()` in the parent process.
|
|
201
|
+
|
|
202
|
+
To change the title, `processtitle` uses the following methods:
|
|
203
|
+
* Changing the content of native (not Python's) `argv[0]` (while preserving the rest of `argv` and relocating `environ`).
|
|
204
|
+
* If `fork_safe_only` is `False` undocumented Launch Services calls
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
### Windows
|
|
208
|
+
|
|
209
|
+
On Windows you can see the process by looking at the process command line. You can see the command lines of running
|
|
210
|
+
processes in two ways:
|
|
211
|
+
|
|
212
|
+
1. Using powershell's `Get-WmiObject Win32_Process` call:
|
|
213
|
+
```powershell
|
|
214
|
+
Get-WmiObject Win32_Process | Select-Object ProcessId, CommandLine
|
|
215
|
+
```
|
|
216
|
+
If you use `cmd` as your command interpreter you can achieve the same effect via:
|
|
217
|
+
```bat
|
|
218
|
+
powershell -c "Get-WmiObject Win32_Process | Select-Object ProcessId, CommandLine"
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
2. In Task Manager details view. If the "Command Line" column is not present, right-click the columns header,
|
|
222
|
+
choose "Select columns" and check "Command Line" entry in the list.
|
|
223
|
+
|
|
224
|
+
To change the title, `processtitle` uses modifies/replaces partially-documented [RTL_USER_PROCESS_PARAMETERS](https://learn.microsoft.com/en-us/windows/win32/api/winternl/ns-winternl-rtl_user_process_parameters) via undocumented or partially documented calls.
|
|
225
|
+
|
|
226
|
+
### BSDs
|
|
227
|
+
|
|
228
|
+
On {Free|Net|Open}BSD you will be able to see the process title in the output of `ps` or `top` commands, as well,
|
|
229
|
+
as with any other tool that displays process info. All of these platforms will, in general, add the original
|
|
230
|
+
executable name (e.g. `python3`) to the actual title either as a prefix or a suffix.
|
|
231
|
+
|
|
232
|
+
To change the title, `processtitle` uses documented `setproctitle()` call ([FreeBSD](https://man.freebsd.org/cgi/man.cgi?query=setproctitle&sektion=3&format=html), [NetBSD](https://man.netbsd.org/NetBSD-10.1/setproctitle.3), [OpenBSD](https://man.openbsd.org/setproctitle.3)).
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
### Illumos
|
|
236
|
+
|
|
237
|
+
On Illumos by default the `ps` command shows process title captured at process creation. To see the current one pass
|
|
238
|
+
the `-F` [option](https://man.omnios.org/man1/ps).
|
|
239
|
+
|
|
240
|
+
To change the title, `processtitle` changes the content of native (not Python's) `argv[0]` (while preserving the rest of `argv` and relocating `environ`).
|
|
241
|
+
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# processtitle
|
|
2
|
+
|
|
3
|
+
This Python extension module allows you to customize process "title" as reported by `ps`, `top`, Activity Monitor,
|
|
4
|
+
Task Manager and similar tools.
|
|
5
|
+
|
|
6
|
+
It is similar to the well known [py-setproctitle](https://github.com/dvarrazzo/py-setproctitle) module but,
|
|
7
|
+
not being constrained by backward compatibility, does things a bit differently and, hopefully, makes things more convenient
|
|
8
|
+
for a user. (If you are already familiar with `py-setproctitle` make sure to read [differences from py-setproctitle](#differences-from-py-setproctitle) section.)
|
|
9
|
+
|
|
10
|
+
Modifying process title is useful in many cases. When you have many Python scripts, or, worse, many instances of the
|
|
11
|
+
same Python script running on your system it is very hard to understand which one is which, if all you see in your process list
|
|
12
|
+
is "Python" or "python3 same-script". Using this module allows your script to specify _what it is for_ or _what it is doing_
|
|
13
|
+
to be shown in the process list instead.
|
|
14
|
+
|
|
15
|
+
<!-- TOC depthfrom:2 -->
|
|
16
|
+
|
|
17
|
+
- [Platform support](#platform-support)
|
|
18
|
+
- [Requirements](#requirements)
|
|
19
|
+
- [Installing](#installing)
|
|
20
|
+
- [Usage](#usage)
|
|
21
|
+
- [Thread and other safety](#thread-and-other-safety)
|
|
22
|
+
- [Differences from py-setproctitle](#differences-from-py-setproctitle)
|
|
23
|
+
- [Platform details](#platform-details)
|
|
24
|
+
- [Linux](#linux)
|
|
25
|
+
- [macOS](#macos)
|
|
26
|
+
- [Windows](#windows)
|
|
27
|
+
- [BSDs](#bsds)
|
|
28
|
+
- [Illumos](#illumos)
|
|
29
|
+
|
|
30
|
+
<!-- /TOC -->
|
|
31
|
+
|
|
32
|
+
## Platform support
|
|
33
|
+
|
|
34
|
+
The module will happily _run_ and do nothing on any [compatible system](#requirements) but the ones where it
|
|
35
|
+
actually _works_ (i.e. changes the process title) are: Linux, macOS, Windows, {Free|Net|Open}BSD and Illumos. See
|
|
36
|
+
[platform details](#platform-details) below for more information about each platform.
|
|
37
|
+
|
|
38
|
+
In all cases only reasonably recent versions of each platform are supported. No attempt is made to work
|
|
39
|
+
on ancient Linux kernels, Windows XP etc. etc. If you are stuck with a very old system your best bet is
|
|
40
|
+
[py-setproctitle](https://github.com/dvarrazzo/py-setproctitle).
|
|
41
|
+
|
|
42
|
+
## Requirements
|
|
43
|
+
|
|
44
|
+
* Python >= 3.10 capable of loading native extensions
|
|
45
|
+
* If your platform doesn't have a binary wheel available, you will need:
|
|
46
|
+
* A C++ compiler capable of compiling C++20 (GCC 10.2 or above and CLang 13 or above are known to work)
|
|
47
|
+
* Python development libraries available (like `python3-dev` package in most Linux distributions)
|
|
48
|
+
|
|
49
|
+
## Installing
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install processtitle
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import processtitle
|
|
59
|
+
|
|
60
|
+
processtitle.prepare(...optional config params...)
|
|
61
|
+
|
|
62
|
+
if not processtitle.set_to("my fancy process"):
|
|
63
|
+
print("ooops, process title couldn't be set")
|
|
64
|
+
else:
|
|
65
|
+
print(f"last set process title is {processtitle.last_set()}")
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The `processtitle.prepare` currently has the following keyword-only optional parameters defined:
|
|
69
|
+
|
|
70
|
+
`fork_safe_only: bool = False`
|
|
71
|
+
: use only such external libraries and/or APIs that
|
|
72
|
+
are safe if your process later performs a `fork` **without** `exec`.
|
|
73
|
+
Currently this is only relevant on macOS where APIs needed to update title in Activity Monitor
|
|
74
|
+
are **not** fork-safe and will cause crashes if used together with `fork` without `exec`.
|
|
75
|
+
|
|
76
|
+
If you wish to enable debug output from this module you can use standard `logging` machinery:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import logging
|
|
80
|
+
|
|
81
|
+
logging.basicConfig(...)
|
|
82
|
+
logging.getLogger("processtitle").setLevel(logging.DEBUG)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Alternatively, you can use `py-setproctitle` compatible method by setting `SPT_DEBUG` environment variable
|
|
86
|
+
to a non-empty value (which is not "0"). For example:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
SPT_DEBUG=1 your_script_that_uses_processtitle
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Thread and other safety
|
|
93
|
+
|
|
94
|
+
`processtitle` _itself_ is thread-safe - all its operations are protected by a mutex. However,
|
|
95
|
+
_the effects_ of changing process title are not. On every platform, changing the title modifies
|
|
96
|
+
some globals process information. If this information is accessed by another thread at the same
|
|
97
|
+
time Bad Things Will Happen. Therefore, it is advisable to only change the title before other
|
|
98
|
+
threads are running or when you are absolutely sure they are suspended.
|
|
99
|
+
|
|
100
|
+
On some platforms, `processtitle` modifies pointers visible to native code (for example `argv[1]...` and
|
|
101
|
+
`environ` on many Unix systems). It never deallocates the memory pointed by these so any native code that
|
|
102
|
+
uses cached values of such pointer should be safe. Python's `sys.argv` and `os.environ` should be
|
|
103
|
+
completely unaffected by any of these manipulations.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Differences from py-setproctitle
|
|
107
|
+
|
|
108
|
+
The most notable difference between `processtitle` and `py-setproctitle` is that this library requires you
|
|
109
|
+
to call `processtitle.prepare()` before setting the process title. Absolutely nothing is done prior to `prepare` -
|
|
110
|
+
just importing the module has no side effects. The `prepare()` method arguments allow you to customize library
|
|
111
|
+
behavior on platforms where multiple incompatible behaviors are possible. Currently this affects only macOS
|
|
112
|
+
(see [macOS details](#macos) below) but in the future might be extended to other platforms.
|
|
113
|
+
|
|
114
|
+
In addition:
|
|
115
|
+
|
|
116
|
+
* There is **no** requirement to import `processtitle` as early as possible. It does
|
|
117
|
+
not rely on Python interpreter state which may be changed by other libraries
|
|
118
|
+
* There is no general "get process title" call (instead you can query the last title _you set_ via `last_set()`).
|
|
119
|
+
This is because querying the original title might not be possible on some platforms.
|
|
120
|
+
* Currently there are no "set/get _thread_ title" calls. If there is any interest, they may be added in the future.
|
|
121
|
+
* `processtitle` supports Windows. At the time of this writing `py-setproctitle` does not.
|
|
122
|
+
* Wherever possible `processtitle` avoids tinkering with `argv` and relies on other safer, documented or
|
|
123
|
+
semi-documented methods.
|
|
124
|
+
* `processtitle` uses standard Python `logging` module to produce diagnostic output rather than just printing to
|
|
125
|
+
`stdout`. (For compatibility, `SPT_DEBUG` environment variable is also supported - it simply sets the default
|
|
126
|
+
logging level for this module to `logging.DEBUG`)
|
|
127
|
+
* `processtitle` is written in C++, not C, so it requires a reasonably modern C++ compiler when binary wheels
|
|
128
|
+
are not available.
|
|
129
|
+
* `processtitle` does not support old or no longer maintained operating systems like AIX, HP-UX etc.
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
## Platform details
|
|
133
|
+
|
|
134
|
+
### Linux
|
|
135
|
+
|
|
136
|
+
On Linux you will be able to see the process title in the output of `ps` or `top` commands, as well, as with any other
|
|
137
|
+
tool that displays process info. Note that on some Linux variants (e.g. Alpine) the title might be prefixed or suffixed
|
|
138
|
+
by the original process executable name. For example: `{python3} your title`.
|
|
139
|
+
|
|
140
|
+
To change the title, `processtitle` uses the following methods:
|
|
141
|
+
* [PR_SET_MM](https://www.man7.org/linux/man-pages/man2/PR_SET_MM.2const.html) call, if available and works.
|
|
142
|
+
* Otherwise [PR_SET_NAME](https://www.man7.org/linux/man-pages/man2/PR_SET_NAME.2const.html)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### macOS
|
|
146
|
+
|
|
147
|
+
On macOS there are 2 independent places where process title is shown: `ps`, `top` and similar commands and
|
|
148
|
+
Activity Monitor. They take information from completely different places and modifying one doesn't modify the
|
|
149
|
+
other. Unfortunately, the API required to change the title for Activity Monitor **cannot be used if your process
|
|
150
|
+
later fork()-s without exec()**. If used in such a process, the forked process will most likely crash randomly and
|
|
151
|
+
unpredictably. Note that some popular libraries such as `gunicorn` may use fork() internally.
|
|
152
|
+
|
|
153
|
+
> [!IMPORTANT]
|
|
154
|
+
> Using fork without exec in Python on macOS (or any other platform) is, in general, dangerous because you rarely know
|
|
155
|
+
> for sure whether the libraries your code depends upon are fork-safe. This is why `multiprocessing` library
|
|
156
|
+
> [avoids fork by default](https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods)
|
|
157
|
+
> on macOS and, recently, on all platforms.
|
|
158
|
+
|
|
159
|
+
Because of this issue, if you must use fork() on macOS you have two options:
|
|
160
|
+
|
|
161
|
+
1. Pass `fork_safe_only=True` argument to `processtitle.prepare()` in the parent process. Doing so will prevent
|
|
162
|
+
use of any non-fork-safe APIs but will also preclude customized process title from being shown in Activity Monitor.
|
|
163
|
+
|
|
164
|
+
2. Alternatively, if feasible, call `processtitle.prepare()` **after** the last `fork()` in the parent process.
|
|
165
|
+
|
|
166
|
+
To change the title, `processtitle` uses the following methods:
|
|
167
|
+
* Changing the content of native (not Python's) `argv[0]` (while preserving the rest of `argv` and relocating `environ`).
|
|
168
|
+
* If `fork_safe_only` is `False` undocumented Launch Services calls
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
### Windows
|
|
172
|
+
|
|
173
|
+
On Windows you can see the process by looking at the process command line. You can see the command lines of running
|
|
174
|
+
processes in two ways:
|
|
175
|
+
|
|
176
|
+
1. Using powershell's `Get-WmiObject Win32_Process` call:
|
|
177
|
+
```powershell
|
|
178
|
+
Get-WmiObject Win32_Process | Select-Object ProcessId, CommandLine
|
|
179
|
+
```
|
|
180
|
+
If you use `cmd` as your command interpreter you can achieve the same effect via:
|
|
181
|
+
```bat
|
|
182
|
+
powershell -c "Get-WmiObject Win32_Process | Select-Object ProcessId, CommandLine"
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
2. In Task Manager details view. If the "Command Line" column is not present, right-click the columns header,
|
|
186
|
+
choose "Select columns" and check "Command Line" entry in the list.
|
|
187
|
+
|
|
188
|
+
To change the title, `processtitle` uses modifies/replaces partially-documented [RTL_USER_PROCESS_PARAMETERS](https://learn.microsoft.com/en-us/windows/win32/api/winternl/ns-winternl-rtl_user_process_parameters) via undocumented or partially documented calls.
|
|
189
|
+
|
|
190
|
+
### BSDs
|
|
191
|
+
|
|
192
|
+
On {Free|Net|Open}BSD you will be able to see the process title in the output of `ps` or `top` commands, as well,
|
|
193
|
+
as with any other tool that displays process info. All of these platforms will, in general, add the original
|
|
194
|
+
executable name (e.g. `python3`) to the actual title either as a prefix or a suffix.
|
|
195
|
+
|
|
196
|
+
To change the title, `processtitle` uses documented `setproctitle()` call ([FreeBSD](https://man.freebsd.org/cgi/man.cgi?query=setproctitle&sektion=3&format=html), [NetBSD](https://man.netbsd.org/NetBSD-10.1/setproctitle.3), [OpenBSD](https://man.openbsd.org/setproctitle.3)).
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
### Illumos
|
|
200
|
+
|
|
201
|
+
On Illumos by default the `ps` command shows process title captured at process creation. To see the current one pass
|
|
202
|
+
the `-F` [option](https://man.omnios.org/man1/ps).
|
|
203
|
+
|
|
204
|
+
To change the title, `processtitle` changes the content of native (not Python's) `argv[0]` (while preserving the rest of `argv` and relocating `environ`).
|
|
205
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"setuptools>=77.0.3",
|
|
4
|
+
"wheel"
|
|
5
|
+
]
|
|
6
|
+
build-backend = "setuptools.build_meta"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
[tool.setuptools.dynamic]
|
|
10
|
+
version = {attr = "processtitle.__version__"}
|
|
11
|
+
|
|
12
|
+
[tool.setuptools.packages.find]
|
|
13
|
+
where = ["src"]
|
|
14
|
+
|
|
15
|
+
[tool.pytest.ini_options]
|
|
16
|
+
testpaths = ["tests"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
[project]
|
|
20
|
+
name = "processtitle"
|
|
21
|
+
dynamic = ["version"]
|
|
22
|
+
authors= [
|
|
23
|
+
{ name = 'Eugene Gershnik', email='gershnik@hotmail.com'}
|
|
24
|
+
]
|
|
25
|
+
description = 'Customize process "title" as reported by ps and similar tools'
|
|
26
|
+
readme="README.md"
|
|
27
|
+
license = "BSD-3-Clause"
|
|
28
|
+
license-files = ["LICENSE", "Acknowledgments.md"]
|
|
29
|
+
requires-python = ">=3.10"
|
|
30
|
+
keywords = [
|
|
31
|
+
'setproctitle', 'proctitle', 'process title', 'process name'
|
|
32
|
+
]
|
|
33
|
+
classifiers = [
|
|
34
|
+
"Development Status :: 4 - Beta",
|
|
35
|
+
|
|
36
|
+
"Operating System :: POSIX :: Linux",
|
|
37
|
+
"Operating System :: MacOS :: MacOS X",
|
|
38
|
+
"Operating System :: Microsoft :: Windows",
|
|
39
|
+
"Operating System :: POSIX :: BSD :: FreeBSD",
|
|
40
|
+
"Operating System :: POSIX :: BSD :: NetBSD",
|
|
41
|
+
"Operating System :: POSIX :: BSD :: OpenBSD",
|
|
42
|
+
"Operating System :: POSIX :: SunOS/Solaris",
|
|
43
|
+
|
|
44
|
+
"Intended Audience :: Developers",
|
|
45
|
+
|
|
46
|
+
"Topic :: Software Development",
|
|
47
|
+
|
|
48
|
+
"Programming Language :: C++",
|
|
49
|
+
"Programming Language :: Python",
|
|
50
|
+
"Programming Language :: Python :: 3",
|
|
51
|
+
"Programming Language :: Python :: 3.10",
|
|
52
|
+
"Programming Language :: Python :: 3.11",
|
|
53
|
+
"Programming Language :: Python :: 3.12",
|
|
54
|
+
"Programming Language :: Python :: 3.13",
|
|
55
|
+
"Programming Language :: Python :: 3.14",
|
|
56
|
+
|
|
57
|
+
"Typing :: Typed"
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
[project.urls]
|
|
61
|
+
Homepage = 'https://github.com/gershnik/processtitle'
|
|
62
|
+
Documentation = 'https://github.com/gershnik/processtitle'
|
|
63
|
+
Issues = 'https://github.com/gershnik/processtitle/issues'
|
|
64
|
+
Changelog = 'https://github.com/gershnik/processtitle/blob/master/CHANGELOG.md'
|