Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

75%
+4 −0
Q&A How can I schedule a later task in Python?

Use at to schedule the command, using subprocess from Python to invoke at. It doesn't even require shell=True. For example: import shlex, subprocess subprocess.run( # `at` command to run n...

posted 9mo ago by Karl Knechtel‭  ·  edited 9mo ago by Karl Knechtel‭

Answer
#3: Post edited by user avatar Karl Knechtel‭ · 2023-08-31T19:27:42Z (9 months ago)
use shlex.split per trichoplax's suggestion
  • Use [`at`](https://en.wikipedia.org/wiki/At_%28command%29) to schedule the command, using `subprocess` from Python to invoke `at`. It doesn't even require `shell=True`. For example:
  • ```
  • import subprocess
  • subprocess.run(
  • # `at` command to run now
  • "at now +10 minutes".split(),
  • # shell command that `at` will schedule, provided to `at`'s stdin
  • input="python -m this > this.txt",
  • # open stdin in text mode with the default encoding
  • text=True
  • )
  • ```
  • <section class="notice is-warning">
  • The `at` program will detach itself from the terminal, so capturing stdout or stderr from the scheduled task will require a workaround (such as invoking `xterm`, or `tee`ing to a TTY that will be open when the task runs).
  • However, if local mail services are available, and `at` is run from a `su` shell, it will send local mail with the output when the job is completed. Check the man page for details.
  • </section>
  • Use [`at`](https://en.wikipedia.org/wiki/At_%28command%29) to schedule the command, using `subprocess` from Python to invoke `at`. It doesn't even require `shell=True`. For example:
  • ```
  • import shlex, subprocess
  • subprocess.run(
  • # `at` command to run now
  • shlex.split("at now +10 minutes"),
  • # shell command that `at` will schedule, provided to `at`'s stdin
  • input="python -m this > this.txt",
  • # open stdin in text mode with the default encoding
  • text=True
  • )
  • ```
  • <section class="notice is-warning">
  • The `at` program will detach itself from the terminal, so capturing stdout or stderr from the scheduled task will require a workaround (such as invoking `xterm`, or `tee`ing to a TTY that will be open when the task runs).
  • However, if local mail services are available, and `at` is run from a `su` shell, it will send local mail with the output when the job is completed. Check the man page for details.
  • </section>
#2: Post edited by user avatar Karl Knechtel‭ · 2023-08-23T02:36:26Z (9 months ago)
  • Use [`at`](https://en.wikipedia.org/wiki/At_%28command%29) to schedule the command, using `subprocess` from Python to invoke `at`. It doesn't even require `shell=True`. For example:
  • ```
  • import subprocess
  • subprocess.run(
  • # `at` command to run now
  • "at now +10 minutes".split(),
  • # shell command that `at` will schedule, provided to `at`'s stdin
  • input="python -m this > this.txt",
  • # open stdin in text mode with the default encoding
  • text=True
  • )
  • ```
  • Note that the `at` program will detach itself from the terminal, so capturing stdout or stderr from the scheduled task will require a workaround (such as invoking `xterm`, or `tee`ing to a TTY that will be open when the task runs).
  • Use [`at`](https://en.wikipedia.org/wiki/At_%28command%29) to schedule the command, using `subprocess` from Python to invoke `at`. It doesn't even require `shell=True`. For example:
  • ```
  • import subprocess
  • subprocess.run(
  • # `at` command to run now
  • "at now +10 minutes".split(),
  • # shell command that `at` will schedule, provided to `at`'s stdin
  • input="python -m this > this.txt",
  • # open stdin in text mode with the default encoding
  • text=True
  • )
  • ```
  • <section class="notice is-warning">
  • The `at` program will detach itself from the terminal, so capturing stdout or stderr from the scheduled task will require a workaround (such as invoking `xterm`, or `tee`ing to a TTY that will be open when the task runs).
  • However, if local mail services are available, and `at` is run from a `su` shell, it will send local mail with the output when the job is completed. Check the man page for details.
  • </section>
#1: Initial revision by user avatar Karl Knechtel‭ · 2023-08-23T02:16:36Z (9 months ago)
Use [`at`](https://en.wikipedia.org/wiki/At_%28command%29) to schedule the command, using `subprocess` from Python to invoke `at`. It doesn't even require `shell=True`. For example:

```
import subprocess

subprocess.run(
    # `at` command to run now
    "at now +10 minutes".split(),
    # shell command that `at` will schedule, provided to `at`'s stdin
    input="python -m this > this.txt",
    # open stdin in text mode with the default encoding
    text=True
)
```

Note that the `at` program will detach itself from the terminal, so capturing stdout or stderr from the scheduled task will require a workaround (such as invoking `xterm`, or `tee`ing to a TTY that will be open when the task runs).