Name | ipc-sync JSON |
Version |
0.1.0.post1
JSON |
| download |
home_page | None |
Summary | Cross-platform utils for IPC (inter-processing communication) synchronization in Python |
upload_time | 2025-02-17 15:39:36 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT |
keywords |
ipc
cross-platform
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ipc-utils
Cross-platform utils for IPC (inter-processing communication) in Python
You can create a named IPC tool like semaphore or mutex here. Onced you created here, you can use it everywhere in your computer. You can also just open a named IPC tool and use it if it has been created somewhere else before.
## Installation
```bash
pip install ipc-sync
```
## Usage
### Semaphore
A named semaphore is offered.
```python
from ipc_sync import Semaphore
sem = Semaphore("/test_sem", create = True, init_val = 1)
## or if it has been created somewhere else before
# sem = Semaphore("/test_sem", create = False)
with sem.guard():
... # critical section
## or if you don't want to use "with" syntax
# sem.wait()
# try:
# ... # critical section
# finally:
# sem.post()
sem.close()
sem.unlink() # if you want to delete the semaphore.
# Don't do this if you are using it somewhere else.
```
Once you created a named semaphore, you can use it in c/cpp like
```c
#ifdef _WIN32
#define Semaphore HANDLE
Semaphore sem = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, "/test_sem");
#else
#include <semaphore.h>
#define Semaphore sem_t
Semaphore sem = sem_open("/test_sem", 0);
#endif
```
### Mutex
A named mutex is offered.
Note that as posix does not offer named mutex, we use named semaphore with init_val 1 instead.
```python
from ipc_sync import Mutex
mtx = Mutex("/test_mtx", create = True)
## or if it has been created somewhere else before
# mtx = Mutex("/test_mtx", create = False)
with mtx.guard():
... # critical section
## or if you don't want to use "with" syntax
# mtx.acquire()
# try:
# ... # critical section
# finally:
# mtx.release()
mtx.close()
mtx.unlink() # if you want to delete the mutex.
# Don't do this if you are using it somewhere else.
```
Raw data
{
"_id": null,
"home_page": null,
"name": "ipc-sync",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "IPC, cross-platform",
"author": null,
"author_email": "monchin <pazzinter@126.com>",
"download_url": "https://files.pythonhosted.org/packages/64/a6/fe612125e3ea5a1ddf51db40b59e533fcc9c038f36bb762c632ea5564fd9/ipc_sync-0.1.0.post1.tar.gz",
"platform": null,
"description": "# ipc-utils\nCross-platform utils for IPC (inter-processing communication) in Python\n\nYou can create a named IPC tool like semaphore or mutex here. Onced you created here, you can use it everywhere in your computer. You can also just open a named IPC tool and use it if it has been created somewhere else before.\n## Installation\n```bash\npip install ipc-sync\n```\n## Usage\n### Semaphore\nA named semaphore is offered.\n```python\nfrom ipc_sync import Semaphore\n\nsem = Semaphore(\"/test_sem\", create = True, init_val = 1)\n## or if it has been created somewhere else before\n# sem = Semaphore(\"/test_sem\", create = False)\nwith sem.guard():\n ... # critical section\n## or if you don't want to use \"with\" syntax\n# sem.wait()\n# try:\n# ... # critical section\n# finally:\n# sem.post()\n\nsem.close()\nsem.unlink() # if you want to delete the semaphore. \n # Don't do this if you are using it somewhere else.\n```\nOnce you created a named semaphore, you can use it in c/cpp like\n```c\n#ifdef _WIN32\n#define Semaphore HANDLE\nSemaphore sem = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, \"/test_sem\");\n#else\n#include <semaphore.h>\n#define Semaphore sem_t\nSemaphore sem = sem_open(\"/test_sem\", 0);\n#endif\n```\n### Mutex\nA named mutex is offered.\n\nNote that as posix does not offer named mutex, we use named semaphore with init_val 1 instead.\n```python\nfrom ipc_sync import Mutex\n\nmtx = Mutex(\"/test_mtx\", create = True)\n## or if it has been created somewhere else before\n# mtx = Mutex(\"/test_mtx\", create = False)\nwith mtx.guard():\n ... # critical section\n## or if you don't want to use \"with\" syntax\n# mtx.acquire()\n# try:\n# ... # critical section\n# finally:\n# mtx.release()\n\nmtx.close()\nmtx.unlink() # if you want to delete the mutex. \n # Don't do this if you are using it somewhere else.\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "Cross-platform utils for IPC (inter-processing communication) synchronization in Python",
"version": "0.1.0.post1",
"project_urls": {
"Homepage": "https://github.com/monchin/ipc-sync",
"Repository": "https://github.com/monchin/ipc-sync"
},
"split_keywords": [
"ipc",
" cross-platform"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ec8158a1cf825b3aa794eb5f02a88557ed98631606ac5da699e8e87868bdc8c0",
"md5": "29870ebab76ff175c5acecf021a881fd",
"sha256": "db2da55cac5462afd200acf3c9a30a0d85040b8cf80b8dc9815d19c33b7182c6"
},
"downloads": -1,
"filename": "ipc_sync-0.1.0.post1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "29870ebab76ff175c5acecf021a881fd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5523,
"upload_time": "2025-02-17T15:39:34",
"upload_time_iso_8601": "2025-02-17T15:39:34.626747Z",
"url": "https://files.pythonhosted.org/packages/ec/81/58a1cf825b3aa794eb5f02a88557ed98631606ac5da699e8e87868bdc8c0/ipc_sync-0.1.0.post1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "64a6fe612125e3ea5a1ddf51db40b59e533fcc9c038f36bb762c632ea5564fd9",
"md5": "a782815eb928c349ff3b624b21aaa42b",
"sha256": "19f1aa23d6ab062a49534619bd30671fdb47c994726119b9407153a390ecf32a"
},
"downloads": -1,
"filename": "ipc_sync-0.1.0.post1.tar.gz",
"has_sig": false,
"md5_digest": "a782815eb928c349ff3b624b21aaa42b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 4710,
"upload_time": "2025-02-17T15:39:36",
"upload_time_iso_8601": "2025-02-17T15:39:36.348341Z",
"url": "https://files.pythonhosted.org/packages/64/a6/fe612125e3ea5a1ddf51db40b59e533fcc9c038f36bb762c632ea5564fd9/ipc_sync-0.1.0.post1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-17 15:39:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "monchin",
"github_project": "ipc-sync",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ipc-sync"
}