memory access ordering between processes in python 3.6
Hi everyone, I'm looking at building an application that allows lockless interprocess data passing using a ring buffer style (sorta) shared memory zone. My initial plan is to create a shared memory zone (probably using C functions thru ctypes), then write data to it with a writer process, then the reader process comes to read that data in its own time. Basically the zone is read/written using ctypes or memoryview objects. The zone (say 1GB) is split in many small buckets approx 10k in size. Each bucket has a flag either showing 0 (free) or 1 (needs reading) in a header. The flag is reset by the reader when done. and is set by the writer once the full bucket has been written to memory and is ready to be read. I know I have to be carefull to make sure writes appear in the proper order to the reader process (that is : data writen by the writer needs to appear before the flag is set by the writter process, from the point of view of the reader process, which is absolutely not a given on modern cpu). So questions : *does python takes care of that automagically, and that's why I havn't found anything on the subject while googling ? (I imagine that within one single multithreaded process the GIL does that neatly, but what of multiprocess applications ?) *or is there a native mechanism or module that allows to play with memory barriers like C does allow one to (https://www.kernel.org/doc/Documentation/memory-barriers.txt). * or do I have to write my own shims to C functions wrapping C/asm memory barrier instructions ? (sounds lighter weight than pulling in the various python asm modules I have around) Any answers much appreciated. Please don't : * tell me to use message queues (that works with some trickery, it's not the purpose of this question) * tell me to use array from the the multiprocessing module, or the data proxy classes (or explain me if the locking scheme in that context can be lockless :) ) Cheers ! Charlie -- https://mail.python.org/mailman/listinfo/python-list
Doubt with files
hello, im trying to read a rtf or txt file with this python script: with open(dirFichero,'r') as reader: for line in reader: print line the problem is that shown is : {\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf810 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} {\*\expandedcolortbl;;} \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 \f0\fs24 \cf0 1l2m,1svo,1lme} INSTEAD of: 1l2m,1svo,1lme How could I fix it? THANK YOU -- https://mail.python.org/mailman/listinfo/python-list
RE: Doubt with files
>with open(dirFichero,'r') as reader: > for line in reader: > print line > >the problem is that shown is : >{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf810 >{\fonttbl\f0\fswiss\fcharset0 Helvetica;} >{\colortbl;\red255\green255\blue255;} >{\*\expandedcolortbl;;} >\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0 >\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 > >\f0\fs24 \cf0 1l2m,1svo,1lme} > >INSTEAD of: >1l2m,1svo,1lme > >How could I fix it? I do not know exactly what encoding rtf or the txt file has but you can use: with open(dirFichero,'r',encoding='utf-8') as reader: This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. -- https://mail.python.org/mailman/listinfo/python-list
Re: Doubt with files
On Tue, Feb 14, 2017 at 11:13 AM, José Manuel Suárez Sierra wrote: > hello, > im trying to read a rtf or txt file with this python script: > > with open(dirFichero,'r') as reader: > for line in reader: > print line > > the problem is that shown is : > > {\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf810 > > {\fonttbl\f0\fswiss\fcharset0 Helvetica;} > > {\colortbl;\red255\green255\blue255;} > > {\*\expandedcolortbl;;} > > \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0 > > \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 > > > > \f0\fs24 \cf0 1l2m,1svo,1lme} > > > INSTEAD of: > 1l2m,1svo,1lme > > How could I fix it? Your program seems to be faithfully printing out the contents of your rtf file as a txt file, showing all of the rtf formatting code. If you want a different result, I suggest you search online for something like: python read write rtf -- boB -- https://mail.python.org/mailman/listinfo/python-list
Re: Doubt with files
On Tue, Feb 14, 2017 at 11:31 AM, Joaquin Alzola wrote: > >>with open(dirFichero,'r') as reader: > > for line in reader: > > print line >> >>the problem is that shown is : >>{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf810 >>{\fonttbl\f0\fswiss\fcharset0 Helvetica;} >>{\colortbl;\red255\green255\blue255;} >>{\*\expandedcolortbl;;} >>\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0 >>\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 >> >>\f0\fs24 \cf0 1l2m,1svo,1lme} >> >>INSTEAD of: >>1l2m,1svo,1lme >> >>How could I fix it? > > I do not know exactly what encoding rtf or the txt file has but you can use: > > with open(dirFichero,'r',encoding='utf-8') as reader: This won't work. It will still display the rtf format coding, which the OP apparently does not want. -- boB -- https://mail.python.org/mailman/listinfo/python-list
Re: Doubt with files
On Tue, 14 Feb 2017 09:13:48 -0800 (PST), José Manuel Suárez Sierra wrote: > hello, > im trying to read a rtf or txt file with this python script: > > with open(dirFichero,'r') as reader: > for line in reader: > print line > > the problem is that shown is : [suppressing blank lines] > > {\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf810 > {\fonttbl\f0\fswiss\fcharset0 Helvetica;} > {\colortbl;\red255\green255\blue255;} > {\*\expandedcolortbl;;} > \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0 > \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx [snip] > \f0\fs24 \cf0 1l2m,1svo,1lme} > > INSTEAD of: > 1l2m,1svo,1lme > > How could I fix it? An RTF file *is* a text file, with formatting information inserted as text strings. Your program is reading and printing an RTF file. If all you want is the part of the file's content that will be visible when it has been rendered into graphics, you'll need to convert the file from RTF to "plain" text at some point. I'd do that with LibreOffice. Alternativey, I see that there's a PyRTF package that might do what you want from within your Python program. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
WANT: bad code in python (for refactoring example)
Hi, Is there any *just right* python code to refactor? In other words, I'm finding bad code example in python. (background) I'm teaching Python to some novice programmer, and want to show refactoring example to them. (required) * not good code * not too large (for novice programmer) * not too complex (for novice programmer) * released under open source license If you know good material in github or bitbucket to refactor, let me know it. -- regards, kwatch -- https://mail.python.org/mailman/listinfo/python-list
Re: WANT: bad code in python (for refactoring example)
On 14-2-2017 23:44, Makoto Kuwata wrote: > Hi, > > Is there any *just right* python code to refactor? > In other words, I'm finding bad code example in python. > > (background) > I'm teaching Python to some novice programmer, and > want to show refactoring example to them. > > (required) > * not good code > * not too large (for novice programmer) > * not too complex (for novice programmer) > * released under open source license > > If you know good material in github or bitbucket to refactor, > let me know it. > > -- > regards, > kwatch > No code in text form, but I find the following video by Raymond Hettinger very clear about the values of refactoring otherwise seemingly fine code https://youtu.be/wf-BqAjZb8M?t=12m39s code starts at 12 min. 40 sec. It does require a bit of background knowledge about Python and the PEP8 code style and API design. Irmen -- https://mail.python.org/mailman/listinfo/python-list
Re: WANT: bad code in python (for refactoring example)
On Wed, 15 Feb 2017 07:44:03 +0900, Makoto Kuwata wrote: > Hi, > > Is there any *just right* python code to refactor? > In other words, I'm finding bad code example in python. Try looking at the ActiveState website for recipes in Python. Especially look at the ones with negative ratings, but even positively rated recipes are often nonsense. E.g. http://code.activestate.com/recipes/580750 does nothing more that define echo = sys.stdout.write Why not use sys.stdout.write directly? Or print? If I saw somebody using this recipe in production code, in the way shown, I'd refactor it to just use print. There's no advantage to re-inventing the wheel this way. -- Steve -- https://mail.python.org/mailman/listinfo/python-list