Fix crash when spawned job completes very fast

Job can complete before we return from `Job.span()` to
`Scheduler._spawn_job()`, so that `_active_jobs` would not yet contain
the job.

This would print a stack on the console and try to run a second time
the job which can have unexpected effects.

In order to reproduce the issue, in
`buildstream/_scheduler/jobs/job.py`, in `Job.spawn`,
add a call to `time.sleep()` right before call to
`asyncio.get_child_watcher()`.

This fixes issue #857.
1 file changed