Friday, 27 August 2010

A failed attempt to eat some kebabs

I'm taking today off. Work is having a team building day. Well, it is billed as a team building day. But I think it is more of a day where the workers are taken away from work, plied with alcohol, an experience, and a meal in order to prepare them for more upcoming work. The experience this year is go karting. I was thinking that for as many years as they have been having these, I have successfully avoided them. But that's not true, I was reminded in a friend's email that I went to one two years ago.

Anyway, I've been feeling a bit ill so far today, probably because of the pancakes and the radish bun that I bought for breakfast. I tried sitting out on my balcony and getting some fresh air. That was nice and comfortable, but there's a lot of street noise and honking. And the pollution is pretty bad today. I tried drinking the bottle of Tsing Tao beer in my fridge to purge my system. But eventually I reached the point where I had to do something. Remembering a blog post about there being a cheap kebab place down the road and round the corner, I headed out to look for it.

It was definitely there. The embers were burning in the side of the wall of another restaurant. There was a fridge beside it on the side of the footpath. But there was no-one there to man it. I scratched my head for a moment, and then for lack of any idea what else I was going to do, I continued down that street which I hadn't really walked down before.

2010-08-27 - Shanghai - Store - 01 - Supermarket


This is another supermarket. There's a limited selection of goods in it, but they are cheaper than the smaller supermarket that I normally go to. And they had coke zero! Normally I can go to any corner store and they have coke zero in the fridge. But lately, no stores have any coke zero. In fact, that's probably the reason I feel ill. I had to buy some diet pepsi this morning, and it was pretty awful. There I was blaming the street food. Anyway, since the Chinese beer didn't purge my system this morning, I made sure to buy some cold New Zealand beer from their fridge. Luckily there are no fruity laws about having to show ID here in China, just bung the booze and cigarettes on the counter and hand over the cash. Not that I smoke, but if I did, I would of course be able to appreciate that aspect too.

There was another blog post on the same site I linked to above. I walk past these dumplings every day, but the thought strikes me that I never see that many people buying them. And that it looks like they sit there for ages, not so fresh for eating. I'm glad to get some confirmation of this without having to buy any myself.

Street food again

I finally realised that the street vendor who the Ayi at work buy the breakfast food from was not the place across the road from the bank, but the place beside the bank. I had run out of the health food that I normally eat for breakfast, so I decided to go out and get some yogurt. Walking to the small supermarket to get it, I realised this this street vendor and decided to grab some stuff on the way back.

The place is extremely popular. There were about three or four people standing around the lady who used the plastic bag it would be sold in as a glove to pick up what they ordered, and then took their money. She charged me 1 RMB per item I bought, and did the same today when I bought more. I think they only take coins there, but really what would I know I don't speak Chinese. She said stuff at me when I arrived, and I have no idea what she said. I guess I do the same thing when I am talking to people what don't speak English.

2010-08-22 - Shanghai - Street Vendor - 01 - Bagged


The pieces of pancake have bits of what seems to be green onion inside, and have sesame seeds sprinkled over them. When you're in the mood, they are quite a nice savoury snack. But I'm getting to the stage where I would need someone else to eat with them, like chilli to dip them in or something.

2010-08-22 - Shanghai - Street Vendor - 02 - Plated


The other smaller items I bought by mistake. At work they vary the items they buy, and sometimes they have these small similarly shaped buns with a fried filling of what seems to be the large white chinese radish they sell here. These were a lot thinner than those buns, and it turns out they're pretty much a fried bready pastry lump with a glazing of honey inside. Really they were a disappointment. I grabbed a coffee and tried to eat them with it to give them some purpose in life, but they were too dry and bland to make it work.

Sunday, 22 August 2010

stacklesssocket.py, greenlet and blocking operations

It seems like many years ago now, that I wrote stacklesssocket as a hobby project for whatever reason I have since forgotten. By monkey patching a matching synchronous interface to asynchronous resources (i.e. asyncore) over the socket module, a lot of existing Python code that used the socket module would just run when used in an application that also used Stackless Python's tasklets. Andrew Dalke's example illustrates this.

A monkey patch..
I now have a number of hobby projects that only get changed when I have the time, energy and interest to work on them. And as such, this module would only get attention when those other projects used it and encountered a problem. This didn't stop other people from using the module. Whether they still use it I do not know, but the other day I saw that a business that at least used to base their service on it got bought by Google. It is also used internally at C.C.P. temporarily in a situation where their Stackless IO library (still pending open source-ification) is not supported.

Recently, I received an offer of sponsorship to do something I have wanted to do for a long time. I won't mention who is sponsoring me, without getting their permission first. Anyway, the central task within the sponsored work was to get the Python standard library unit tests running against it, and to get the tests (at least the non-UDP ones) passing. This is now done, and apart from two particular UDP unit tests, the module passes the tests for Python 2.6 and 2.7. The module is also compatible with Python 2.5, and won't work any worse with that version than it did before. There are at least some API differences (which exceptions are raised) that it does not specifically support when run against Python 2.5. It is interesting to note however, that given there are only two UDP test failures, it is a good sign that generally the new module changes are naturally correct.

The Python unit test suite uses a lot of thread blocking calls, which also block the Stackless scheduler that manages the tasklets running on the given thread. And often, those tasklets need to do something for the thread blocking call to get what it needs. So, this is not Stackless compatible behaviour. The most common of these calls are time.sleep, select.select and calling acquire on a thread lock. In order to get these working, I've implemented a threading-related module to also do monkey-patching to hand off the work into another thread. Something that also required more work that I would have liked, was working around the constraints that Stackless enforces when scheduling in another thread (there is a scheduler per-thread) and that thread is blocked while waiting for a channel operation. There aren't many users of Stackless' scheduler per thread support, and a few of the rare corner cases need some usage to clean up exactly how they should work.

While it has been an additional goal since stacklessocket was first created to eventually implement a matching suite of modules that can be used to turn any thread blocking operation to a tasklet one, unfortunately I've had to spend my time elsewhere. But we are now with the addition of the threading-related module part of the way there, even if only to a need-driven level so that the Python unit tests will run. I've been envious that gevent has a suite of modules like this, although I have no idea of the extent to which they work. My involvement with greenlet has been to write a module that provided a Stackless-like interface for it, when it was first released. Beyond that, my involvement with anything greenlet related has been to sending an email to a tengentially related mailing list, related to noting that the Python license more than likely applies to any source code that was extracted from Stackless Python (and therefore it can't be MIT licensed within greenlet), both demonstrating my lack of knowledge about how it is used and potentially annoying other people with license complications.

Anyway, if you use this module, I suggest giving the latest version a try. Let me know how it works for you.