Appium confused when 2 iOS devices are plugged in

I have read that it is not possible to test multiple iOS devices in parallel because instruments is a single process tool.
However it should be possible to have 2 or more devices plugged in a Mac and test them sequentially, right?

This seems to be working in if the app to be tested is already installed in both devices. But after testing for some time, removing the apps and running the tests again I found a situation where Appium (instruments, or the tools to install the .ipa file) seem to be confused.

I have set up two appium instances, on different ports, one for each device, specifying its uuid, like “appium -p X -U device1” and “appium -p Y -U device2”

It happens that sometimes I launch a test on the appium instance for device 1 but it installs the app in device 2 if it was not installed already.
Or if the app was installed in device 2, it will say that the app is installed when I run the test in device 1, where the app is not installed.

Is this a known problem?

Is there some way of knowing what is the full command being used to install the app, to see if some command is not receiving the proper UUID?

This is a part of the log of running a test on a device but having the app installed in another one:

info: [debug] Not pre-launching simulator
info: [debug] Creating iDevice object with udid <DEVICE1_UDID>
info: [debug] Checking app install status using: /usr/local/lib/node_modules/appium/build/fruitstrap/fruitstrap isInstalled --id <DEVICE1_UDID> --bundle com.mycompany.test
info: [debug] App is not installed. Will try to install the app.
info: [debug] Installing ipa found at /test.ipa
info: [debug] Creating iDevice object with udid <DEVICE1_UDID>
info: [debug] Nothing found on device, going ahead and installing.

(I would like to know what command is being used to install here)

info: [debug] Starting command proxy.
info: [debug] Instruments socket server started at /tmp/instruments_sock
info: [debug] Starting instruments
info: [debug] Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: Launching instruments
info: [debug] Attempting to run app on real device with UDID <DEVICE1_UDID>
info: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w <DEVICE1_UDID> com.mycompany.test -e UIASCRIPT "/Users/sbruno/Library/Application Support/appium/bootstrap/bootstrap-e8ac4024d20bd709.js" -e UIARESULTSPATH /tmp/appium-instruments
info: [debug] And extra without-delay env: {}
info: [debug] And launch timeouts (in ms): {"global":90000}
info: [debug] [INST STDERR] 2015-01-28 17:09:17.765 instruments[1769:2703] WebKit Threading Violation - initial use of WebKit from a secondary thread.
info: [debug] [INST STDERR] Instruments Usage Error : Specified target process is invalid: com.mycompany.test
info: [debug] [INSTSERVER] Instruments exited with code 255
info: [debug] Killall instruments

This is a part of the log of running a test on a device which has the app not installed, but there is another device plugged in that has the app installed, and it seems to find the app installed there:

info: [debug] On a real device; cannot clean device state
info: [debug] Not setting locale because we're using a real device
info: [debug] No iOS / app preferences to set
info: [debug] Starting iOS device log capture via deviceconsole
info: [debug] Not pre-launching simulator
info: [debug] Creating iDevice object with udid <DEVICE1_UDID>
info: [debug] Checking app install status using: /usr/local/lib/node_modules/appium/build/fruitstrap/fruitstrap isInstalled --id <DEVICE1_UDID> --bundle com.mycompany.test
info: [debug] App is not installed. Will try to install the app.
info: [debug] Installing ipa found at /test.ipa
info: [debug] Creating iDevice object with udid <DEVICE1_UDID>
info: [debug] Bundle found on device, removing before reinstalling.

(The app is not installed in this device, it is in the other, but it seems that it found it installed)

info: [debug] Starting command proxy.
info: [debug] Instruments socket server started at /tmp/instruments_sock
info: [debug] Starting instruments
info: [debug] Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: Launching instruments
info: [debug] Attempting to run app on real device with UDID <DEVICE1_UDID>
info: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w <DEVICE1_UDID> com.mycompany.test -e UIASCRIPT "/Users/sbruno/Library/Application Support/appium/bootstrap/bootstrap-e8ac4024d20bd709.js" -e UIARESULTSPATH /tmp/appium-instruments
info: [debug] And extra without-delay env: {}
info: [debug] And launch timeouts (in ms): {"global":90000}
info: [debug] [INST STDERR] 2015-01-28 17:17:06.263 instruments[1941:4a03] WebKit Threading Violation - initial use of WebKit from a secondary thread.
info: [debug] [INST STDERR] Instruments Usage Error : Specified target process is invalid: com.mycompany.test

(It fails because the app was not installed)

Wouldn’t it be easier to run one appium server and pass different capabilities with different UDIDs?

Right, in this case of running tests sequentially it would be easier, thanks.
I created different appium instances because I was used to do that for android in order to support parallel executions.

However I tried what you say, and for the problem I was describing, using one appium instance and passing the udid made no difference…

By the way. I’m using Appium 1.3.4. Python client 0.11. OS X Mavericks. xcode 6.1.1

The only suggestion I would have is to run one or both Appium instances on VMs running OS X. VMWare Fusion, Virtualbox, etc. let you specify which VM a USB device gets attached to. I work with the Simulator, not physical devices, so this is about the extend of my knowledge.