May 2009
3 posts
1 tag
IO Error From raw_input() in Jython
When I try to use raw_input on my Ubuntu machine in Jython 2.2.1 on Java 1.6.0_07 I get an empty IOError when executing a python file, but not when using a python shell:
-- raw_input.py --
raw_input()
>> jython raw_input.py
Traceback (innermost last):
File "raw_input.py", line 1, in ?
IOError:
-- console --
>>> raw_input()
hello
'hello'
To get round this I just use...
1 tag
Greedy and Reluctant Qualifiers
A common gotcha when using regular expressions occurs when using the default (greedy) qualifiers + ? and *. These qualifiers will attempt to make the longest match they possibly can.
The regular expression:
/'(.*)'/
will successfully match and group the word there in hello 'there', but will actually run on to the last single quote in the string hello 'there' how are 'you', matching there'...
1 tag
Making Java Processes Play Nice
Looking around, it seems that there is no easy way to stop Java from eating all your system resources when running a particularly heavy-going task.
Thankfully my lovely colleague Ben made me aware of a helpful UNIX command called nice.
By prefixing nice to any command you can ask the scheduler to be a bit more kind, running the process at a slightly lower priority to ensure it doesn’t starve...