I'm trying to launch casperjs (a Python launcher script) from pm2 but each time I do I get an error like this
node: ../deps/uv/src/unix/core.c:701: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
Running by hand works fine, just not when launched from pm2. Does pm2 modify the environment in any way that would cause something like this?
Could you provide a gist or some file example?
Are you running it in fork mode? If not try the -x parameter.
yes I was.
pm2 start path/to/casperjs -o casper.out -e casper.out -x --interpreter python -- script.js
Is casper interpreting python or pm2?
Is casper written in python?
I really don't understand the point, nor has the casper knowledge but this doesn't seems to be a pm2 issue.
casperjs in this case is itself a Python script, which is why I though I needed to specify python as the interpreter. The hash bang at the top of the file has /usr/bin/env python. Does that make specifying the interpreter through pm2 redundant or is it still necessary?
Is it this: http://casperjs.org/?
Could you try running:
pm2 start -o casper.out -e casper.out -x --interpreter python path/to/casperjs script.js
I must say, I find it weird using pm2 with a unit tester script.
it does things other than unit testing :). I use it as a more convenient interface to PhantomJS. I'll try that, thanks.
^^ using python to play with JS running a phantom browser and that forever... Weird.
We faced the same error
node: ../deps/uv/src/unix/core.c:701: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
running our nodejs app in fork mode exactly after upgrading from 0.8.2 to 0.8.3. Tested with newer versions — problem exists, before and with 0.8.2 — everything ok.
Could you try with the latest PM2 version and tell me if it still happens ?
The problem still exists with pm2 v0.10.7. I'm using node v0.10.25 on Ubuntu 13.04 (GNU/Linux 3.8.0-35-generic x86_64)
I had the same issue on OSX (Mavericks), Using NodeJS v0.10.32 and PM2 0.10.8. I've even update to NodeJS v0.11.3 with the same result....but I found a WORKAROUND.
Note: Casperjs (casperjs.org) allows you to write some javascript to test or automate tasks simulating a web-browser. It uses either phantomjs (phantomjs.org) or slimerjs (slimerjs.org) to do the actual HTTP requests, but offer simpler ways to manage flow and fill forms. So you can use casperjs+phantomjs or casperjs+slimerjs. I use it with slimerjs.
I opened the casperjs script and seems like it only read some config and execs other javascript . So I just print the line to be executed and got (replace path_here with real data):
slimerjs /usr/local/lib/node_modules/casperjs/bin/bootstrap.js --casper-path=/usr/local/lib/node_modules/casperjs --cli path_here/appCasper.js
If I run that as is (no pm2), it works well
If I run that with pm2:
pm2 start /usr/local/bin/slimerjs -e err.log -o out.log -- /usr/local/lib/node_modules/casperjs/bin/bootstrap.js --casper-path=/usr/local/lib/node_modules/casperjs --cli path_to/appCasper.js
I get the following error:
"Assertion failed: (loop->watchers[w->fd] == w), function uv__io_stop, file ../deps/uv/src/unix/core.c, line 701." and around 15 instance of my app are created and run at the same time.
The slimerjs shell script do a few things and then runs:
export SLIMER_ARGS="/usr/local/lib/node_modules/casperjs/bin/bootstrap.js --casper-path=/usr/local/lib/node_modules/casperjs --cli /src/appCasper.js"
export __SLIMER_ENV="....... __YOUR_ENV_HERE"
"/usr/local/lib/node_modules/slimerjs/lib/slimer/xulrunner/xulrunner" -app /usr/local/lib/node_modules/slimerjs/lib/slimer/application.ini --profile /tmp/slimerjs.3FQMvM9O -no-remote "/usr/local/lib/node_modules/casperjs/bin/bootstrap.js --casper-path=/usr/local/lib/node_modules/casperjs --cli /src/appCasper.js"
So it actually runs the 'xulrunner'... and so I did:
export __SLIMER_ARGS="/usr/local/lib/node_modules/casperjs/bin/bootstrap.js --casper-path=/usr/local/lib/node_modules/casperjs --cli /src/appCasper.js"
pm2 start /usr/local/lib/node_modules/slimerjs/lib/slimer/xulrunner/xulrunner -x -e err.log -o out.log -- -app /usr/local/lib/node_modules/slimerjs/lib/slimer/application.ini --profile /tmp/slimerjs.3FQMvM9O -no-remote /usr/local/lib/node_modules/casperjs/bin/bootstrap.js --casper-path=/usr/local/lib/node_modules/casperjs --cli /src/appCasper.js
And it works!!!
The only issue I see is that im always using the same "--profile /tmp/slimerjs.3FQMvM9O" this way.... will check how to solve and update here. Also note that __SLIMER_ENV seems to be not necessary fotrthis to work.
So, about the bug itself: I still don't know why it happens but note that:
'/usr/local/bin/casperjs' is a python script that will execute '/usr/local/bin/slimerjs'.
'/usr/local/bin/slimerjs' is a bash script that set's some environment variables and runs '/usr/local/lib/node_modules/slimerjs/lib/slimer/xulrunner/xulrunner'
'/usr/local/lib/node_modules/slimerjs/lib/slimer/xulrunner/xulrunner' is a binary
same here:
->watchers[w->fd] == w), function uv__io_stop, file ../deps/uv/src/unix/core.c, line 826.
$ cat run.sh
npm run app%
$ pm2 start run.sh -x --interpreter bash
Has this bug gotten stuck?
I know this issue is old and already closed, but for those who want to have a CasperJS script running with pm2, here is the working command:
pm2 start your_script.js --interpreter=/usr/lib/node_modules/casperjs/bin/casperjs.js
The interpreter path must be absolute and doesn't matter where your CasperJS is installed, it just needs to point the casperjs.js file.
ckeckout this article about using pm2 properly with python: https://blog.pm2.io/managing-python-application-with-pm2/
I created a echosystem file echosystem.config.json
{
"apps": [{
"name": "app_name",
"script": "/the/app/path/my_app.py",
"args": ["-c", "my_config.prod.json"],
"instances": "1",
"wait_ready": true,
"autorestart": false,
"max_restarts": 5,
"interpreter" : "/path/to/venv/bin/python",
}]
}
Run the pm2 service:
$ pm2 start echosystem.config.json
$ pm2 -v
3.2.8