Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68282 > unrolled thread
| Started by | Zachary Ware <zachary.ware+pylist@gmail.com> |
|---|---|
| First post | 2014-03-12 09:12 -0500 |
| Last post | 2014-03-12 09:12 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How do we pass default argument value to create thread object? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-03-12 09:12 -0500
| From | Zachary Ware <zachary.ware+pylist@gmail.com> |
|---|---|
| Date | 2014-03-12 09:12 -0500 |
| Subject | Re: How do we pass default argument value to create thread object? |
| Message-ID | <mailman.8091.1394633665.18130.python-list@python.org> |
On Wed, Mar 12, 2014 at 8:09 AM, Piyush Verma <114piyush@gmail.com> wrote:
> Hi,
>
> I am using Thread class to create threads.
> <CODE>
> thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"])
> thread.start()
> </CODE>
>
> This code is throwing compilation error(Ipython).
> In [19]: import threading
>
> In [20]: def Fun(agr1, arg2, arg3=None):
> ....: pass
> ....:
>
> In [21]: thread = threading.Thread(target=Fun, args=[arg1, arg2,
> arg3="val"])
> ------------------------------------------------------------
> File "<ipython console>", line 1
> thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"])
> ^
> SyntaxError: invalid syntax
>
> How do we pass the value to default arguments while creating thread object?
Use the 'kwargs' argument:
thread = threading.Thread(target=Fun, args=[1, 2], kwargs={'arg3': "val"})
See http://docs.python.org/3.4/library/threading#threading.Thread for more info.
Hope this helps,
--
Zach
Back to top | Article view | comp.lang.python
csiph-web