Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python Script Spawned by Cron or Systemd doesn't write files..?
Hi all,

I've written a Raspberry Pi application (Ubuntu Mate) that's essentially a timed camera. Every 30 seconds, it snaps an image and writes it to disk.

When I start the application manually from the terminal, it works as expected.

When I configure the script to execute automatically at startup, (using crontab or systemd - It needs to be executed as root) the script runs without any error, but no images are written to the disk.

Any idea of what may be going on?

My script:
import time
from camera import *
import cv2

count = 0

while True:
    # Open camera

    # Turn on Light
    Camera01.Light.fill((255, 255, 255, 255))

    # Snap Image
    image = Camera01.GiGe.GrabOne(1000)

    # Convert image to OpenCV Array
    image = cv2.cvtColor(image.Array, cv2.COLOR_BAYER_BG2BGR)

    # Save image to disk
    cv2.imwrite('saved_images/image'+str(count)+'.png', image)

    # Turn off Light
    Camera01.Light.fill((0, 0, 0, 0))

    # Close camera

    # Increment counter
    count = count + 1

The camera class:
import neopixel
import board
from pypylon import pylon

class Camera01:
    GiGe = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
    Light = neopixel.NeoPixel(board.D18, 16, bpp=4, auto_write=True)
My crontab:
@reboot python3 /var/www/camera/ > /var/log/cron/crontab.log 2>&1
Dance I figured it out, I never specified a working directory. When I setup the application as a service, there is a "WorkingDirectory" assignment that I was missing. Once specified, it's working as it should.

Description=Time lapse camera application

ExecStart=/usr/bin/python3 /var/www/camera/

Please mark as solved (this helps moderators when scanning so many queries)

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Automating to run python script 100 times by changing parameters pmt 0 97 Aug-10-2019, 02:58 PM
Last Post: pmt
  Help with PyInstaller + Script "Failed to Execute Script" ironfelix717 2 150 Jul-31-2019, 02:18 PM
Last Post: ironfelix717
  I need help with a python script nicopython 4 186 Jul-29-2019, 12:16 AM
Last Post: jonnin
  Python Script to repeat Photoshop action in folders and subfolders silfer 2 104 Jul-25-2019, 03:12 PM
Last Post: silfer
  Asyncio StreamReader read method doesn't respect timeout when using SSL dukadahake 0 76 Jul-24-2019, 11:55 AM
Last Post: dukadahake
  Best method: Python script called from another app, package as complete executable ironfelix717 2 108 Jul-24-2019, 07:39 AM
Last Post: DeaD_EyE
  How do I copy files faster with python? steckinreinhart619 7 372 Jul-19-2019, 11:47 AM
Last Post: perfringo
  Is this possible in Python? Auto-Send-to-printer on script run? pcsailor 8 967 Jul-19-2019, 09:33 AM
Last Post: perfringo
  Pynput doesn't recognize shift button and special characters VirtualDreamer 0 99 Jul-17-2019, 11:55 AM
Last Post: VirtualDreamer
  How do I edit saved Python 3 script? Mocap 1 137 Jul-17-2019, 08:41 AM
Last Post: perfringo

Forum Jump:

Users browsing this thread: 1 Guest(s)