|
2 | 2 |
|
3 | 3 | using Serialization: serialize_cycle, deserialize_cycle, writetag,
|
4 | 4 | serialize_typename, deserialize_typename,
|
5 |
| - TYPENAME_TAG, reset_state, serialize_type |
| 5 | + TYPENAME_TAG, TASK_TAG, reset_state, serialize_type |
6 | 6 | using Serialization.__deserialized_types__
|
7 | 7 |
|
8 | 8 | import Serialization: object_number, lookup_object_number, remember_object
|
@@ -102,6 +102,26 @@ function serialize(s::ClusterSerializer, t::Core.TypeName)
|
102 | 102 | nothing
|
103 | 103 | end
|
104 | 104 |
|
| 105 | +function serialize(s::ClusterSerializer, t::Task) |
| 106 | + serialize_cycle(s, t) && return |
| 107 | + if istaskstarted(t) && !istaskdone(t) |
| 108 | + error("cannot serialize a running Task") |
| 109 | + end |
| 110 | + writetag(s.io, TASK_TAG) |
| 111 | + serialize(s, t.code) |
| 112 | + serialize(s, t.storage) |
| 113 | + bt = t.backtrace |
| 114 | + if bt !== nothing |
| 115 | + if !isa(bt, Vector{Any}) |
| 116 | + bt = Base.process_backtrace(bt, 100) |
| 117 | + end |
| 118 | + serialize(s, bt) |
| 119 | + end |
| 120 | + serialize(s, t.state) |
| 121 | + serialize(s, t.result) |
| 122 | + serialize(s, t.exception) |
| 123 | +end |
| 124 | + |
105 | 125 | function serialize(s::ClusterSerializer, g::GlobalRef)
|
106 | 126 | # Record if required and then invoke the default GlobalRef serializer.
|
107 | 127 | sym = g.name
|
@@ -231,6 +251,23 @@ function deserialize(s::ClusterSerializer, t::Type{<:CapturedException})
|
231 | 251 | return CapturedException(capex, bt)
|
232 | 252 | end
|
233 | 253 |
|
| 254 | +function deserialize(s::ClusterSerializer, ::Type{Task}) |
| 255 | + t = Task(nothing) |
| 256 | + deserialize_cycle(s, t) |
| 257 | + t.code = deserialize(s) |
| 258 | + t.storage = deserialize(s) |
| 259 | + state_or_bt = deserialize(s) |
| 260 | + if state_or_bt isa Symbol |
| 261 | + t.state = state_or_bt |
| 262 | + else |
| 263 | + t.backtrace = state_or_bt |
| 264 | + t.state = deserialize(s) |
| 265 | + end |
| 266 | + t.result = deserialize(s) |
| 267 | + t.exception = deserialize(s) |
| 268 | + t |
| 269 | +end |
| 270 | + |
234 | 271 | """
|
235 | 272 | clear!(syms, pids=workers(); mod=Main)
|
236 | 273 |
|
|
0 commit comments