Why does this Python program freeze/hang:
$ ls -l freeze.py
-rwx------ 1 rick rick 24 Oct 27 11:40 freeze.py
$ cat freeze.py
import re
print "hello"
$ ./freeze.py
C-c
And why does this Haskell program also freeze/hang:
$ ls -l freeze.hs
-rwxrw-r-- 1 rick rick 46 Oct 27 11:22 freeze.hs
$ cat freeze.hs
import Text.Regex.Posix
main = print "hello"
$ ./freeze.hs
C-c
(I know this is a rudimentary/rookie mistake. But I doubt that I'm the first or last person to make this mistake ...so I'll document it here so future klutzes like me can google it.)
These scripts freeze because they are actually shell scripts. These shell scripts are actually running the import
command-line program ... which is provided by the ImageMagick package:
$ sh freeze.hs
C-c
$ which import
/usr/bin/import
$ man import | head -10
... import - saves any visible window on an X server and outputs it as an image file.
$ import screenshot.ps
... and here notice the mouse icon changes to a cross-hair icon ...
... so then press the mouse button to finish this operation ...
$ file screenshot.ps
screenshot.ps: PostScript document text conforming DSC level 3.0, Level 1
So my kudos to the ImageMagick crew for providing a nice, silent command-line operation.
At least on various Linux-based operating system, these scripts trigger operation of the import
command-line program. BSD, Windows, MacOS, etc may respond differently.
Here is correct operation of the script with the Python interpreter and ghc
compiler:
$ python freeze.py
hello
$ runghc freeze.hs
"hello"
Or alternatively, include the #!
shebang:
$ ls -l no_freeze.py
-rwx------ 1 rick rick 46 Oct 27 11:44 no_freeze.py
$ cat no_freeze.py
#!/usr/bin/env python
import re
print "hello"
$ ./no_freeze.py
hello
And the same for Haskell:
$ ls -l no_freeze.hs
-rwx------ 1 rick rick 68 Oct 27 11:26 no_freeze.hs
$ cat no_freeze.hs
#!/usr/bin/env runghc
import Text.Regex.Posix
main = print "hello"
$ ./no_freeze.hs
"hello"
On my MacOS computer, I'm getting this error because some part of my X11 setup isn't finished. For those who didn't install X11, I imagine you would get the command not found error.
$ import screenshot
Version: ImageMagick 6.9.5-0 Q16 x86_64 2016-07-02 http://www.imagemagick.org
...
import: delegate library support not built-in `' (X11) @ error/import.c/ImportImageCommand/1297.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With