What if? Say you want to execute something in a python sub-process and you want to read and resend all output data, no matter how big they are?
The simplest solution to use pipe is BAD idea - pipe has it's own buffer and what's worse size of this buffer is constant and cannot be changed by using some smart fnctl call any more. Let's run a simple test:
On my laptop I'm not able to send more than 64kB at a time, moreover its completely hanging:
Hmmm... So how can you send more than that? Let's say this way:
Use a simple manager, man! More info here.
There is also possibility to use shared memory objects (read this), but those are rather for storing not so huge amount of data.
Disclaimer: Before use, read the contents of the package insert or consult your physician or pharmacist because each drug used improperly threatens your life or health.
wtorek, 19 lutego 2013
środa, 6 lutego 2013
Revert words in a sentence.
Revert words in a sentence, so " The quick brown fox jumped over the lazy dog." becomes "dog. lazy the over jumped fox brown quick The" .
In C:
In C++:
In py:
52 > 27 > 4!
poniedziałek, 8 października 2012
python graph implementation
And now as I have promised in my previous post.
it needs some more work, i.e. dumping to Graphviz format, but apart of that it is working quite well.
poniedziałek, 1 października 2012
metaclass with dynamic creation of properties
Meteclass with dynamic properties creation:
Written as helper class for my graph implementation (metaclass for nodes, edges and graph itself).
środa, 26 września 2012
yet another Observer pattern in python
Observer sniffing a particular attribute from Observable class. This little spy is notified every time watched attribute is changing its value.
Observers are hold in weakref.WeakValueDictionary to avoid crashes in case they would disappear (i.e. being collected and deleted by gc). And here is the source code:
środa, 8 sierpnia 2012
python traced class
With metaclass programming in python you can easily created a class tracing all updates to its attributes:
All objects using Traced metaclass are able to tell you which attributes have been changed. To get list of updated attributes (or keys when using TracedDict or indexes in case of TracedList) just call updated member function.
There is only one shortage: attributes defined and set inside __init__ (real instance attributes like instanceAttribute in TracedTest class) will be put into updated list when calling constructor. To avoid this behavior and trace changed during lifetime of object you need at call at ther very last line in constructor self.updated( reset = True ) (or uncomment last line in above example).
Subskrybuj:
Posty (Atom)