30 11 2012 Python javascript Tweet
pythonã§ã¡ãã£ã¨ããã¯ãã¼ã©ã¼ãæ¸ãã¦çµå¤ã§æµãããæã«ãå¤ä¸ã«è½ã¡ããããã¨æéããã£ãããªãã®ã§ãæ»ãã§ãçãè¿ãããã«ãã¦ãããããã¨ãããã
追è¨121203
ã¯ã¦ãã§ææãããéã
forever start -c python crawler.py
ã§è¯ãã£ããããã¥ã¡ã³ãã«ã¡ããã¨æ¸ãã¦ãã£ãã
node.jsã§æ¸ããå ´åã«ã¯foreverã使ãã¦ä¾¿å©ã ããä»ã®è¨èªã§æ¸ããå ´åã«ã¯child_processã§åããã»ã¹ã«ãã¦å¼ã³åºãã°ããã®ã§ãjavascriptãã¡ãã£ã¨æ¸ãã¦ããã°ãPythonã§ãPerlã§ãHaskellã§ããªãã§ã使ããã
ã§ãjavascriptãæ¯åæ¸ãã®ã¯(å¿ããã)é¢åãªã®ã§foreverç¨ã®javascriptãåºåããã¹ã¯ãªãããpythonã§æ¸ãã¦ã¿ã(foreverizeã£ã¦ããåå)ã
#!/usr/bin/env python import sys js_str = """var spawn = require('child_process').spawn; var app = spawn('{}', [{}]); app.stdout.on('data', function(data) {{ console.log('stdout: ' + data); }}); app.stderr.on('data', function(data) {{ console.log('stderr: ' + data); }}); app.on('exit', function(code) {{ console.log('exit code: ' + code); }}); """ if __name__ == '__main__': if len(sys.argv) < 2: print "Usage: {} [command]".format(sys.argv[0]) else: command = sys.argv[1] options = "" if len(sys.argv) >= 2: options = ",".join(["'{}'".format(op) for op in sys.argv[2:]]) print js_str.format(command, options)
使ãæ¹ã¯ç°¡å
foreverize python crawler.py > crawler.js forever start crawler.js
ããã§ããã¼ã¢ã³åããã¦å¤ã§ãå®å¿ã