New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process SysV-Semaphore support #49975
Comments
Please could we have an API in the Python Core for PROCESS ie. I'd like to be able to : Because of being un-able to do this, the attached "psem.*" |
To Build: $ gcc -fPIC -shared -o psempy.c psempy.so -I/usr/include/python2.6
-L/usr/lib/python2.6 -lpython2.6 && mv psempy.so psem.so
$ dd if=/dev/urandom of=app1_20090407.01.log bs=1000000 count=1
$ python
>>> import sys, os, re, datetime, psem, psem_example
>>> psem_example.compress_log( "app1", "2009", "04", "07", "01", "bzip",
"app1_20090407.01.log");
0 Example psem.so using program that compresses logs |
Example Python use of psem.so Parallel ForEach : Log Compressor Usage: $ gcc -o psem.so -fPIC -shared psempy.c -I/usr/include/python2.6
-L/usr/lib/python2.6 -lpython2.6
$ dd if=/dev/urandom bs=1000000 count=1 of=app1_20090407.01.log
$ python
Python 2.6 (r26:66714, Oct 16 2008, 00:21:12)
[GCC 4.2.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, os, re, datetime, psem, psem_example
>>> psem_example.compress_log( "app1", "2009", "04", "07", "01", "bzip",
"app2_20090407.02.log");
0
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
>>> Now, one can time for example 16 runs of the above command with |
$ time /usr/bin/python2.6 ./psem_example.py 2>&1 | tee log
Do you really want to run test using 16 1MB log files ? Y/Ny
generating files 0..15
generating file 0
generating file 1
generating file 2
generating file 3
generating file 4
generating file 5
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.783862 s, 1.3 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.890675 s, 1.1 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.831693 s, 1.2 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.84914 s, 1.2 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.885601 s, 1.1 MB/s
generating file 6
generating file 7
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.942455 s, 1.1 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.282143 s, 3.5 MB/s
generating file 8
generating file 9
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.41776 s, 2.4 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.292488 s, 3.4 MB/s
generating file 10
generating file 11
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.396643 s, 2.5 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.2736 s, 3.7 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.316026 s, 3.2 MB/s
generating file 12
generating file 13
generating file 14
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.349368 s, 2.9 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.364177 s, 2.7 MB/s
generating file 15
compressing files 0..15
compressing file 0
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.495831 s, 2.0 MB/s
1+0 records in
1+0 records out
1000000 bytes (1.0 MB) copied, 0.229301 s, 4.4 MB/s
compressing file 1
compressing file 2
compressing file 3
compressing file 4
compressing file 5
compressing file 6
compressing file 7
compressing file 8
compressing file 9
compressing file 10
compressing file 11
compressing file 12
compressing file 13
compressing file 14
compressing file 15 real 0m10.700s |
I suggest a new sys SysV-semaphore API : sys.semget( sem_key, sem_nsems, sem_flags)
sys.SEM_KEY_ANY = 0
sys.SEM_UNDO = 0x1000 /*chain of atomic kernel UNDO operations*/
sys.SEM_GETPID = 11 /* get sempid */
sys.SEM_GETVAL = 12 /* get semval */
sys.SEM_GETALL = 13 /* get all semval's */
sys.SEM_GETNCNT = 14 /* get semncnt */
sys.SEM_GETZCNT = 15 /* get semzcnt */
sys.SEM_SETVAL = 16 /* set semval */
sys.SEM_SETALL = 17 /* set all semval's */
#if ( ! defined(__sun__) ) || defined ( __GNU__ )
sys.SEM_STAT = 18
sys.SEM_INFO = 19
#endif
sys.semop(semid, sops, nsops) sys.semtimedop(semid, sops, nsops,
timeout
)
sys.semctl(semid, semnum, cmd, ...); |
PS: Timings for x86{-32,-64} or ia{32,64} architectures are likely
|
C source code implementing "psem.*" python module functions |
Contrast what I had to do to perform a process semaphore operation -- Perl 5.10.0 documentation --
operations such as signalling and waiting. OPSTRING must be a packed
in perlipc, IPC::SysV , and IPC::SysV::Semaphore documentation. Nice ! Why can't Python provide something similar ? Then my example psempy.c module could be implemented in 100% pure I'm bringing this issue up here so as to gain some feedback from |
In bpo-5672 Martin said: If somebody would provide a patch that adds prctl to the posix module, However, you are talking about a System V call, not a posix call, so I suggest bringing this up on python-ideas. (BTW, sys is for python system stuff, not OS system stuff (which goes in |
Thanks for responding ! I also think that the the Solaris Python should provide support for prctl . Actually, the example code I submitted for this bug report also raises another, Maybe I should raise another "fflush() support required" bug ? Thanks & Regards, On Thursday 09 April 2009 19:31:31 you wrote:
|
On Sat, 11 Apr 2009 at 09:29, jvdias wrote:
You are welcome. If you want something to happen, though,
Is there some way in which sys.stdout.flush() is not equivalent to "an
If it's a real issue, yes. But I don't think it is. --David |
I stumbled across this bug report while looking for an mmap-related Obviously it's not in the standard library, but it is pretty well It's for Python 2.x only. http://semanchuk.com/philip/sysv_ipc/ Hope this helps |
jvdias, have you looked at what the multiprocessing module offers? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: