Decorators in Python are just fantastic. Here are a few I've used in
Postr. Update: the wonderful James Hensbridge expanded
the decorators, so I've updated this post.
def threaded(f):
def wrapper(*args, **kwargs):
t = threading.Thread(target=f, args=args, kwargs=kwargs)
t.setDaemon(True)
t.start()
wrapper.__name__ = f.__name__
return wrapper
This decorator (stolen from
O'Reilly)
calls the method in a new thread, so execution returns straight away. I
use this for long-running tasks that cannot be handled in an asynchronous
manner (such as the photo uploading in Postr, which currently uses
urllib). The main thread returns straight away so the interface
doesn't block, and the uploads continue in the background.
Of course this new thread cannot just call GTK+ methods, as GTK+ itself
isn't threadsafe. So, I have another decorator that causes a method to be
always executed in the main loop by scheduling an idle handler that calls
it.
def as_idle(f):
def wrapper(*args, **kwargs):
event = threading.Event()
ret = []
def task():
ret.append(f(*args, **kwargs))
event.set()
return False
gobject.idle_add(task)
event.wait()
return ret[0]
wrapper.__name__ = f.__name__
return wrapper
Erich Schubert requested return values, so James added those too. The
calling function will block until the idle handler has called the
decorated function. I've split the decorators out into a separate file in
Postr, so you can
view the
latest version online.
Magic stuff!
I have three machines located under my desk at home:
- rock, an SMP i386 machine on which I'm typing
this,
- ska, an MVME167 machine that has a 68040 processor and is
supposed to be a Debian/m68k buildd host,
- and newwave, a Macintosh Quadra 700, which does not have
enough RAM to be used as a buildd, but which I use to do some m68k-based
hacking on.
A few months ago, the last two had died with various problems that
had seemed to be disk-related; both gave an error in the
firmware—with ska's error obviously being more... detailed... than
the 'unhappy mac' error icon that newwave gave me.
Today, I powered both on again.
newwave didn't even give me
a hiccup; it booted right away, even if it needed to do a rather
extensive
fsck run.
ska did take a little more work,
unfortunately; it seems to boot, but it does give me SCSI errors, too.
At least it's managed to make it to a login prompt, however, so I can
have a chance at fixing it.
Interestingly, just as I finished the above paragraph, and less than
half a minute after it made it to said login prompt, it breaks down
rather horribly:
scsi0 channel 0 : resetting for second half of retries.
SCSI bus is being reset for host 0 channel 0.
scsi0 : DCMD DBC=0x98080000, DNAD=0x2cec6c (virt 0x002cec6c)
DSA=0x3ad300 (virt 0x003ad300)
DSPS=0x2060000, TEMP=0x3ad154 (virt 0x003ad154), DMODE=0xe0
SXFER=0x58, SCNTL3=0x0
phase=MSGIN, 0 bytes in SCSI FIFO
SCRATCH=0x3ad300, saved2_dsa=0x3ad300
scsi0 : DSP 0x2cec64 (virt 0x002cec64) ->
0x2cec64 (+1a1) : 0x98080000 0x02060000
0x2cec6c (+1a3) : 0xc0000004 0x002ce5c4 0xfff47010
0x2cec78 (+1a6) : 0x80080000 0x002cfb80
0x2cec80 (+1a8) : 0x98080000 0x00030000
0x2cec88 (+1aa) : 0x50000000 0x002cede0
0x2cec90 (+1ac) : 0x60000200 0x00000000
scsi0 : issue queue
scsi0 : dsa at phys 0x3ab188 (virt 0x003ab188)
+ 64 : dsa_msgout length = 2282225664, data = 0x2ce7d8 (virt 0x002ce7d8)
+ 60 : select_indirect = 0xfff47010
+ 56 : dsa_cmnd = 0x2ce5c4 result = 0x8888, target = 27147, lun = 0, cmd = VENDOR SPECIFIC(0xe5) c4 ff f4 70 10 88 08 00 00
+ 48 : dsa_next = 0x0
scsi0 target 27147 : sxfer_sanity = 0x0, scntl3_sanity = 0x0
script : 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
Unable to handle kernel NULL pointer dereference at virtual address 0000004a
Oops: 00000000
PC: [<000bfae2>]
SR: 2700 SP: 01ad9cd8 a2: 01ad8000
d0: 00000001 d1: 00002622 d2: 0000000a d3: 00000008
d4: 002d2704 d5: 002d14e0 a0: 00000000 a1: 0015aefc
Process ntp_time_as_com (pid: 775, stackpage=01ad9000)
Frame format=7 eff addr=01ad9d5c ssw=0505 faddr=0000004a
wb 1 stat/addr/data: 0005 003ab188 01ad9d60
wb 2 stat/addr/data: 0005 0016f8b5 0000abd6
wb 3 stat/addr/data: 0005 01ad9d40 0000000a
push data: 01ad9d60 0000adec 0015aee0 00000001
Stack from 01ad9d40:
0000000a 00000008 002d2704 002d14e0 002ce5c4 002ce140 003ab188 0000ac4a
000bfe68 002ce5c4 0013e781 00000000 00000018 002d2704 00000000 00000000
0000ac4a 003ab188 002d14e0 002ce000 000bfefc 002d14e0 003ab188 0013e576
00000000 0000ac4a 002d14e0 003ad300 98080000 000bf586 fff47000 002cec98
002ce000 000c02d4 002d14e0 003a5200 00000000 000b2704 00000018 00000020
00000000 00000000 002d14e0 002ce000 000bf912 002d14e0 002d14e0 00000001
Call Trace:
[<0000ac4a>] [<000bfe68>] [<0013e781>] [<0000ac4a>]
[<000bfefc>] [<0013e576>] [<0000ac4a>] [<000bf586>]
[<000c02d4>] [<000b2704>] [<000bf912>] [<000b6c4c>]
[<000b5f24>] [<000b6a04>] [<000b6c4c>] [<000b6c4c>]
[<000b65b6>] [<0013d5fe>] [<00002404>] [<000beb82>]
[<000bd206>] [<000bf022>] [<000bf4d6>] [<000bed46>]
[<000833fe>] [<00004e52>] [<00003b86>] [<0000c00c>]
Code: 2c68 004a 4878 0180 2f0c 47fa 0c8a 4e93 508f 2a0b
Kernel panic: Aiee, killing interrupt handler!
In interrupt handler - not syncing
aw.
Oh well, at least I've got one more working machine now. Only need to
update it from unstable as it was 41 days ago to today's unstable. Going
to take a while, I fear.
So i have travelled to Slovakia again, for a weekend this time.
I have been painting window frames. Since i have a new iPod (4G nano,
black, yummy), i could also listen to music (Tristania, In Flames,
Kamelot). The last time, it was somewhat of a patience exercise, but
this time... I guess i got better at painting and maybe i have become
more patient, too :). It was pretty enjoyable, more than i would have
thought a work like that could be. And i am sure the music helps, too.
(The next day)
And to continue the last blog... There, i have concluded that hardship
was important factor in becoming better:
And apart from hardship... Problem is, hardship alone, if it stays the
same, is not enough to make people change. It is the change from
contentment to unhappiness, that drives people forward. Because in
that change, one starts to change, and hardship together with dynamics
helps a lot. Static, unchanging hardship will only do little to change
a person. One can get used to it, like to anything else. Like to
contentment. So an initial change can start a cascade. Like for me,
breakup caused a domino effect. The change alone brought a lot of
hardship with it, and i had to change to accomodate to it. And the
change in me provoked more changes and so on. I have learned many new
things, or, things i have learned before but went unnoticed took my
notice. And in light of such things, i had to change again, because i
knew i couldn't be happy any other way.
A human being is as good as dead, when captured in a period of
stagnation, in an unchanging moment that lasts. Only through change,
through dynamics of life, we are alive. A man that does not change is
a statue, a dead piece of matter, only useful as a memento. And that
was what i have become, and now the statue is again starting to move,
to breathe, to live. Because there is just no perfection that one
could capture in a moment. No matter how perfect a moment, if frozen,
the perfection decays, the little cracks are noticed. That is why
trying to freeze time is futile, trying to preserve. One cannot enter
the same stream twice. Life is a constant change, and this constant
change is its only manifestation. Take the change away and you take
the life away.
The past is important. The past is what resulted into present, and
present is what makes future. Every moment, in a succession of
moments, is important. But without the moment before and the moment
after, the moment does not mean anything. The moment is void, without
predecessor and successor. We move in time, and the motion is what
becomes important, not the points we moved through. They are only
important in the relation to our trajectory, not in isolation. And so
is the direction which we take, the vector of our motion, and the
shifts in direction.
There is no eternity, only the eternity of its own
absence. Immortality and death are the same, the very same
notion. Because every time we change, there is a little death and a
little birth. And immortality is only possible in
staticness. Immortality is a point in time, without motion. And
without motion, there is no life to be.
And same goes for relationships. Make a relationship immortal and you
make it die. Relationship needs a possibility of death to live. Like
humans, like every living being. Without death, there is no life. The
transition from being into non-being is essential, because it is the
precondition to change. As i have already described, every change is a
death followed by rebirth, but the entity reborn is not the one that
has died. And therefore, without the ability to die, there is no
ability to change. And death, the conventional death, as we know it,
is just a death without rebirth. Something dies, and there is nothing
more to take its place. But... The death makes others change. And
therefore, the one who dies definitively, is again reborn, as part of
those others that have died, but haven't died, but are reborn. And the
one definitely dead enters those new, reborn creatures, as a little
fraction of them. And the cycle of life is closed, and the change can
perpetuate itself.
Every day, i die a thousand times. But there are deaths that are
important and deaths that go unnoticed. And most of the important ones
are only noticed in retrospect, by a being that resulted, after many
hours, or days, or weeks or even longer. And many more deaths. We only
exist through our succession, because only what is born from us
remembers what we were. And the very moment we are born, we die again,
and a new being remembers. The memory lives on, but the beings are
already dead. And the memory changes as well, because memory itself
does not mean anything, only the being possesing it can give it
meaning. And every successive being that we become gives it a slightly
different meaning.
And so the delicate, complex dynamics of individual life are
established. Not only the living being changes itself, but the
memories of the previous beings change. There is certain gravity
toward stagnation, because often the changes are only very slight, and
the being remembers his predecessors that were fairly happy and tries
to remain so. Because the bigger the change, the bigger risk. And
therefore all beings are susceptible to stagnation, to the stasis cell
of past success. Because past success is one's own enemy, even if it
is something that is a precondition to one's own being. So we need to
learn to live with our past success, but to not try to revive it. The
effort to bring back past is a wasted, contraproductive effort. It
seems so, it is almost natural, that if there was happiness in the
past, restoring the same past will bring the same happiness. But
there, that is not true, in the light of previous paragraphs. The trap
is so obvious, that description is probably redundant, but let me do
it once again anyway, maybe because i have fallen in it so many times
already. Yes, the trap is in the stagnation, in absence of new
things. Because even if one cannot restore the original condition no
matter how much he tries, one can, and that is for sure, replicate it
very closely. And that way lies a trap, a temporary (or even
permanent) thermal death of stagnation.
(Later that day, outside, on a nearby hill)
And now, like before, there's nothing more to stand between me and
myself. I sit in the grass, alone. My being alone complements me, in a
way. There are waves in the grass, as air moves. Music is playing,
apart from the few houses i can see downhill, my only connection with
the rest of people. And this what belongs to me, this paper, this
pen. This book by Italo Calvino that Enrico Zini has given me. If on a
winter's night a traveller. But it is late summer. I can see vineyard
in distance, on a slope different from mine. I call this slope mine
because i am the one sitting there. And the time to collect the grapes
is close. And here, next to me, an apple tree, with red apples on it.
And a white butterfly in the distance, beating the air with its light,
small wings. And i blow away a tiny spider who has lost its way on my
trousers. I feel being part of all this around me, and still so
foreign. And the butterfly appears again, but it may be a different
one.
The sun shines behind my back, alhtough i sit in shade of a tree. And
neither the sun nor the tree are my enemies, or my friends. But still,
i feel sympathy for both of them, one gives me light and warmth and
the other shields me from too much of it. And the setting, the scenery
soothes my senses, my mind, my feelings. Here, i am close to the
loving mother of us, living beings, the nature. Here she is tender and
forgiving and caresses my hair and it feels good.
And these feelings, i would love to pass on, to other people, so they,
too, could feel well. But i see that this is not quite
possible. Although these lines will hopefully give something to
someone, they probably can't carry what i feel. And i would bring
someone with myself here, so they could feel it with me. But presence
of other person would spoil it, it would be something else then. Maybe
beautiful in a way, different from this one, maybe very pleasant. I
love people, and when i see them happy, it fills me with gladness.
(And in the evening, on a train...)
And here i am, moving with speed, from one place to another. The
speed, sound of loud music in my ears, the landscape drifting away. I
could say i was happy, happy in the sense of change, everything
changing around me, sun setting behind distant horizon, the train
moving through the country. The semaphore lights. In the headphones,
heavy guitar riffs competing with the roaring of the train. Cold air
blowing in my face, flowing in my hair.
And now in another train, sitting in a compartment with stranger, a
girl, trying to guess who she could be, from her dress, from what she
is reading, from cues. Who she could become. What she means to me, a
passing stranger on the path of life. I have been reading the Calvino
book till now, but i thought i could write down my thoughts before
they perish, like they do. It is fairly silent now here, even while we
are on a train. The engine and the outside are muffled, the window and
the door are closed. We are in a strange kind of privacy with this
girl, neither knowing anything about the other. I, writing this text
here, she reading some sort of magazine. Looking up from what we do at
occasions. The train is accelerating now, and the sounds are more
intense. It is a bit shaky, too. My hearing is still lightly impaired
from the loud music from the previous train.
We arrived to a station. Short stop, then another long motion. Always
toward Brno, toward my flat, toward the night and tomorrow. The girl
is reading a horse races program. Here, i intrude her privacy and
write that here. I hope she wouldn't mind. I don't have a name other
than "the girl" for her, since all the words we exchanged was me
asking whether i can sit down in the compartment and her answer. And i
suppose i won't say anything and she won't, neither. Maybe a goodbye.
And now, we share a sort of almost intimacy. Two lone people in a
compartment, tired and waiting to arrive somewhere. An invisible bond
between us, doesn't mean anything, just that element at random brought
us there together, for a short moment. Chances are, we won't ever meet
again. And still, she is almost falling asleep, with her feet up, like
if i were a trustworthy friend of old. And i feel sympathy for that, i
feel honoured by a trust given by a complete stranger. She seems
comfortable, feeling safe. And it feels good to have that trust, it
feels important. It nearly gives warm fuzzies.
(To be continued, further...)